#include "programregexp.h"
#include "instructionEnum.h"
#include <QDebug>
#include "programsimplecheck.h"
#include "instructionEnum.h"
#define D_DEBUG_FLAG 0
ProgramRegExp::ProgramRegExp()
{

    initCommonRegExp();
    simpleCheck=new ProgramSimpleCheck;
}



void ProgramRegExp::initCommonRegExp()
{
    //指令正则表达式涉及ｈｍｉ的　programcheck.cpp文件进行语法检查，同时涉及到ProgramDelegate::analysisＸＸＸＸInstruction()

    // 常数
    str_rx_num= "(\\s*\\-?\\d+\\s*)" ;
    // 浮点数
    str_rx_float="(\\s*(\\-?\\d+)(\\.\\d+)?\\s*)";
    // 所有字符
    str_rx_anyStr = "([\\s\\S]*)";
    //注释
    srt_rx_notes =  "(\\s*(;?)(\\s*\\n)?\\s*(//[\\s\\S]*)?)" ;

    // 运算符
    str_rx_opt_DOWNTO_TO= "(\\s+(DOWNTO|TO)\\s+)"; // 循环 FOR
    str_rx_opt_AND_OR= "(\\s*(AND|OR)\\s+)" ;//条件 IF
    str_rx_opt_ON_OFF= "(\\s*(ON|OFF)\\s*)" ;//开关 IO
    str_rx_opt_Operation= "(\\s*(\\+|\\-|\\*|\\/|DIV|MOD)\\s*)" ;//计算
    str_rx_opt_Operation_2= "(\\s*(\\+|\\-)\\s*)" ;//计算
    str_rx_opt_Match= "(\\s*[>=<]{1,2}\\s*)" ; //比较,
    str_rx_opt_Match_2= "(\\s*(\\=|\\<\\>)\\s*)" ; //比较, 部分指令只能使用＝ 或者 <>

    // 中括号值匹配格式： [ R[i] ] ，  [ i ]
    str_rx_zkh_i = "(\\s*\\[\\s*(\\d+|((R|AR)\\s*\\[\\s*\\d+\\s*\\]))\\s*\\]\\s*)" ;
    // 中括号值匹配格式： [ R[i], R[i] ] ，  [ i, j ] ,    [ 5, R[i] ]
    str_rx_zkh_ij = "(\\s*\\[\\s*(\\d+|((R|AR)\\s*\\[\\s*\\d+\\s*\\]))\\s*,\\s*(\\d+|((R|AR)\\s*\\[\\s*\\d+\\s*\\]))\\s*\\]\\s*)" ;
    // 中括号值匹配格式： [ R[i], R[i], R[i] ],    [ i, j, k ] ,    [ i,  R[i], 6 ]
    str_rx_zkh_ijk = "(\\s*\\[\\s*(\\d+|((R|AR)\\s*\\[\\s*\\d+\\s*\\]))\\s*,\\s*(\\d+|((R|AR)\\s*\\[\\s*\\d+\\s*\\]))\\s*,\\s*(\\d+|((R|AR)\\s*\\[\\s*\\d+\\s*\\]))\\s*\\]\\s*)" ;

    // 普通暂存器:  R[ R[i] ],    R[i]
    str_rx_R_i = QString( "(\\s*(R|AR)%1)").arg( str_rx_zkh_i);
    // 位置寄存器:  P[i] ,   PR[i],   PR[i, j] ; 不同格式后面运算的条件不一样
    str_rx_PR_i = QString( "(\\s*(P|PR)%1)").arg( str_rx_zkh_i);
    str_rx_PR_ij = QString( "(\\s*(PR)%1)").arg( str_rx_zkh_ij);

    // 栈板寄存器:  PL[i] ,    PL[i, j, k] ; 不同格式后面运算的条件不一样 ,    [*, R[1], 3 ]
    str_rx_PL_i = QString( "(\\s*(PL)%1)").arg( str_rx_zkh_i );
    str_rx_PL_ijk_val = "\\s*(\\d+|\\d+\\-\\d+|R\\s*\\[\\s*\\d+\\s*\\]|\\*)\\s*";
    str_rx_PL_ijk = QString( "(\\s*\\[\\s*%1,%2,%3\\s*\\]\\s*)").arg( str_rx_PL_ijk_val ).arg( str_rx_PL_ijk_val ).arg( str_rx_PL_ijk_val );

    // PR[GP1: 9]= UTOOL[GP1: 1]
    str_UF_i = QString( "(\\s*(UFRAME)%1)").arg( str_rx_zkh_i );
    str_TF_i = QString( "(\\s*(UTOOL)%1)").arg( str_rx_zkh_i );

    // 字符串寄存器( 暂不支持 )
    str_rx_SR  = QString( "(\\s*(SR)%1)").arg( str_rx_zkh_i );
    str_rx_io_i_all = QString("(\\s*(DI|DO|RI|RO|AI|AO|SI|SO|UI|UO|GI|GO)%1)").arg( str_rx_zkh_i ) ;
    // 定时器： TIMER|TIMER_OVERFLOW
    str_rx_TIMER = QString("(\\s*(TIMER|TIMER_OVERFLOW)%1)").arg( str_rx_zkh_i ) ;

    // R[i] 运算表达式
    str_rx_ri_tmp1 =  QString( "(%1|%2)" ).arg( str_rx_num ).arg( str_rx_R_i  );
    //带小跨号的运算
    str_rx_R_i_ALL =  QString("(\\(*(%1|%2|%3|%4|%5)\\)*)").arg( str_rx_float ).arg( str_rx_R_i ).arg( str_rx_io_i_all ).arg( str_rx_PR_ij ).arg( str_rx_TIMER );
    str_rx_R_i_opt =  QString("(%1%2%3(%4%5)*)")
            .arg( str_rx_R_i )
            .arg( "\\s*=\\s*" )
            .arg( str_rx_R_i_ALL )
            .arg( str_rx_opt_Operation )
            .arg( str_rx_R_i_ALL ) ;
    str_rx_R_i_opt_2 =  QString("(%1%2(%3|%4))")
            .arg( str_rx_R_i )
            .arg( str_rx_opt_Match )
            .arg( str_rx_R_i )
            .arg( str_rx_float );

    // PL 运算表达式 ,   PL[ R[3] ] = PL[3]+  [ 3, R[2], * ]
    str_rx_PL_opt_tmp1 =  QString( "(\\(*(%1|%2)\\)*)" ).arg( str_rx_PL_i ).arg( str_rx_PL_ijk  );
    str_rx_PL_opt = QString( "(%1%2%3(%4%5)*)" )
            .arg( str_rx_PL_i )
            .arg( "\\s*=\\s*" )
            .arg( str_rx_PL_opt_tmp1 )
            .arg( str_rx_opt_Operation )
            .arg( str_rx_PL_opt_tmp1 ) ;
    str_rx_PL_opt_2 = QString( "(%1%2%3)" )
            .arg( str_rx_PL_i )
            .arg( str_rx_opt_Match )
            .arg( str_rx_PL_opt_tmp1 );

    // PR 运算表达式
    str_rx_PR_opt_tmp1 =  QString( "(\\(*(%1|%2|%3|(LPOS|JPOS))\\)*)" ).arg( str_rx_PR_i  ).arg( str_TF_i ).arg( str_UF_i  );
    //PR[ i ]
    str_rx_PR_i_opt =  QString( "(%1%2%3(%4%5)*)" )
            .arg( str_rx_PR_i )
            .arg( "\\s*=\\s*" )
            .arg( str_rx_PR_opt_tmp1 )
            .arg( str_rx_opt_Operation_2 )
            .arg( str_rx_PR_opt_tmp1 ) ;
    //PR[ i , j ]
    str_rx_PR_ij_opt =  QString( "(%1%2%3(%4%5)*)" )
            .arg( str_rx_PR_ij  )
            .arg( "\\s*=\\s*" )
            .arg( str_rx_R_i_ALL )
            .arg( str_rx_opt_Operation )
            .arg( str_rx_R_i_ALL ) ;
    //PR - ALL
    str_rx_PR_opt = QString( "(%1|%2)" )
            .arg( str_rx_PR_i_opt )
            .arg( str_rx_PR_ij_opt ) ;

    // IO 运算表达式
    //IO指令->输入输出：DO[R[3]]= OFF  ,  AO[]= 4217.2 ,  RI[ i ]= DI[ 5 ]
    str_rx_io_i_a = QString("(\\s*(DI|DO|RI|RO|SI|SO|UI|UO)%1)").arg( str_rx_zkh_i ) ;
    str_rx_IO_a_opt = QString( "(%1%2(%3|%4|%5))" )
            .arg( str_rx_io_i_a )
            .arg( "\\s*=\\s*" )
            .arg( str_rx_opt_ON_OFF )
            .arg( str_rx_io_i_a )
            .arg( str_rx_R_i );
    str_rx_IO_a_opt_2 = QString( "(%1%2(%3|%4|%5))" )
            .arg( str_rx_io_i_a  )
            .arg( str_rx_opt_Match_2 )
            .arg( str_rx_opt_ON_OFF )
            .arg( str_rx_io_i_a )
            .arg( str_rx_R_i );

    str_rx_io_i_b = QString("(\\s*(AI|AO|GI|GO)%1)").arg( str_rx_zkh_i ) ;

    str_rx_IO_b_opt = QString( "(%1%2(%3|%4))" )
            .arg( str_rx_io_i_b  )
            .arg( "\\s*=\\s*" )
            .arg( str_rx_float )
            .arg( str_rx_R_i );

    str_rx_IO_b_opt_2 = QString( "(%1%2(%3|%4))" )
            .arg( str_rx_io_i_b  )
            .arg( str_rx_opt_Match )
            .arg( str_rx_float )
            .arg( str_rx_R_i );

    str_rx_IO_opt = QString( "(%1|%2)" )
            .arg( str_rx_IO_a_opt )
            .arg( str_rx_IO_b_opt ) ;

    str_rx_IO_opt_2 = QString( "(%1|%2)" )
            .arg( str_rx_IO_a_opt_2 )
            .arg( str_rx_IO_b_opt_2 );
    //IO指令->脉冲，   // DO[R[3]]= PULSE , 1.2 sec,   DO[1]= PULSE
    str_rx_io_i_c = QString("(\\s*(DO|RO|SO|UO)%1)").arg( str_rx_zkh_i ) ;
    str_rx_PULSE_opt = QString( "(%1%2%3(,%4%5)?)" )
            .arg( str_rx_io_i_c  )
            .arg( "(\\s*=\\s*)" )
            .arg( "(\\s*(PULSE)\\s*)" )
            .arg( str_rx_float )
            .arg( ("sec") ) ;
    /// 寄存器指令
    str_rx_REG =  QString ( "(%1|%2|%3|%4)" )
            .arg( str_rx_PL_opt )
            .arg( str_rx_R_i_opt )
            .arg( str_rx_PR_i_opt )
            .arg( str_rx_PR_ij_opt ) ;
    ///IO指令
    str_rx_IO = QString( "(%1|%2)" )
            .arg( str_rx_IO_opt  )
            .arg( str_rx_PULSE_opt) ;
    /// 调用指令：CALL *,  RUN *
    str_rx_CALL = "(\\s*(CALL)\\s+.+)";
    /// 调用指令： RUN *
    str_rx_RUN = "(\\s*(RUN)\\s+.+)";
    /// 标签指令：LBL[ R[i] ] ， LBL[ i ] , 暂不支持注释
    str_rx_LBL= QString("(\\s*(LBL)\\s*\\[(%1|%2)\\]\\s*)").arg( str_rx_num ).arg( str_rx_R_i );
    /// 跳转指令：JMP LBL[ R[i] ]
    str_rx_JMP= QString("(\\s*(JMP)\\s+%1)").arg( str_rx_LBL );
    /// 坐标系指令
    str_rx_USER_FRAME = QString("%1%2").arg("\\s*(UFRAME)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*=\\s*(PR)\\s*(\\[)\\s*(\\d+)\\s*(\\])").arg(srt_rx_notes);
    str_rx_USER_NUM = QString("%1%2").arg("\\s*(UFRAME_NUM)\\s*\\=\\s*([R]?\\[?\\d+\\]?)").arg(srt_rx_notes);
    str_rx_UFRAME = QString("%1|%2").arg(str_rx_USER_FRAME).arg(str_rx_USER_NUM);

    str_rx_TOOL_FRAME = QString("%1%2").arg("\\s*(UTOOL)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*=\\s*(PR)\\s*(\\[)\\s*(\\d+)\\s*(\\])").arg(srt_rx_notes);
    str_rx_TOOL_NUM = QString("%1%2").arg("\\s*(UTOOL_NUM)\\s*\\=\\s*([R]?\\[?\\d+\\]?)").arg(srt_rx_notes);
    str_rx_UTOOL = QString("%1|%2").arg(str_rx_TOOL_FRAME).arg(str_rx_TOOL_NUM);

    /// 运动指令： J  L  C  A
    // J
    str_rx_motion_J=  "(\\s*(J)\\s+(P|PR)\\s*\\[[\\s\\S]+(FINE|CNT).*)";
    // L
    str_rx_motion_L=  "(\\s*(L)\\s+(P|PR)\\s*\\[[\\s\\S]+(FINE|CNT).*)";
    // C
    str_rx_motion_C =    "((\\s*(C)\\s+(P|PR)\\s*\\[\\s*[\\s\\S]*)|(\\s*(P|PR)\\s*\\[[\\s\\S]+(FINE|CNT).*))";
    str_rx_motion_C_1=  "(\\s*(C)\\s+(P|PR)\\s*\\[\\s*[\\s\\S]*)";
    str_rx_motion_C_2=  "(\\s*(P|PR)\\s*\\[[\\s\\S]+(FINE|CNT).*)";
    // A
    str_rx_motion_A=  "(\\s*(A)\\s+(P|PR)\\s*\\[[\\s\\S]+(FINE|CNT).*)";
    //ALL
    str_rx_MOTION=  QString("(%1|%2)")
            .arg( "(\\s*(J|L|A)\\s+(P|PR)\\s*\\[[\\s\\S]+(FINE|CNT).*)" )
            .arg( str_rx_motion_C );
    //堆栈头
    str_rx_PALL_HEAD=  QString("(\\s*(PALLETIZING-)\\s*(B_|BX_|E_|EX_)\\d+\\s*)");
    //堆栈运动
    str_rx_PALL_MOTION=  QString("((J|L)\\s*(PAL_)\\d+\\s*\\[\\s*((A_|R_)\\d+|(BTM))\\s*\\]\\s*\\d+[\\s\\S]+(FINE|CNT).*)");
    //辅助点？
    str_rx_PALL_HAND=  QString("(\\s*(HAND)\\d+\\s*(OPEN|CLOSE)\\s*)");
    //堆栈结束
    str_rx_PALL_END=  QString("(\\s*(PALLETIZING-END_)\\d+\\s*)");
    /// 堆栈指令:
    str_rx_PALLETIZING =  QString("(%1|%2|%3|%4)")
            .arg( str_rx_PALL_HEAD )
            .arg(str_rx_PALL_MOTION  )
            .arg(str_rx_PALL_HAND  )
            .arg(str_rx_PALL_END  );

    str_rx_wait_delay =QString(  "(\\s*(WAIT)\\s+((%1\\s*(sec)\\s*)|%2))" )
            .arg( str_rx_float )
            .arg( str_rx_R_i );

    str_rx_wait_else =QString(  "(\\s*(WAIT)\\s+(%1|%2)((%3(%4|%5)){0,4})(\\s*\\,\\s*(TIMEOUT)\\s*%6)?\\s*((%7\\s*(sec)\\s*)|%8)?)" )
            .arg( str_rx_IO_opt_2 )
            .arg( str_rx_R_i_opt_2 )
            .arg( str_rx_opt_AND_OR )
            .arg( str_rx_IO_opt_2 )
            .arg( str_rx_R_i_opt_2 )
            .arg( str_rx_LBL )
            .arg(str_rx_float)
            .arg(str_rx_R_i);
    //str_rx_opt_AND_OR

    /// 等待指令 : WAIT 10.5sec    , WAIT R [ 1 ] ,   WAIT R [ 2 ] <> 1 , TIMEOUT LBL [ 1 ] , WAIT R [ R [ 1 ]] >= 200
    str_rx_WAIT = QString( "(%1|%2)" )
            .arg( str_rx_wait_delay )
            .arg( str_rx_wait_else ) ;
    // 判断条件
    str_rx_requirement =  QString( "(%1|%2|%3|%4|%5)" )
            .arg( str_rx_IO_opt_2 )
            .arg(str_rx_PL_opt_2)
            .arg( str_rx_R_i_opt_2 );
    // 处理
    str_rx_proc= QString( "(\\s*,\\s*(%1|%2|%3))" ).arg( str_rx_JMP ).arg(  str_rx_CALL ).arg( str_rx_RUN ) ;
    /// IF 指令  , 部分条件只能用( <> = )判断符号
    str_rx_IF = QString( "(\\s*(IF)\\s*%1(%2%3){0,4}%4)" )
            .arg( str_rx_requirement )
            .arg( str_rx_opt_AND_OR )
            .arg( str_rx_requirement )
            .arg( str_rx_proc )  ;
    /// SELECT 指令
    str_rx_SELECT_start = QString( "(\\s*(SELECT)\\s*%1=%2%3)" )
            .arg( str_rx_R_i )
            .arg( str_rx_ri_tmp1 )
            .arg( str_rx_proc )  ;

    str_rx_SELECT_mid = QString( "(\\s*=%1%2)" )
            .arg( str_rx_ri_tmp1 )
            .arg( str_rx_proc );

    str_rx_SELECT_end = QString( "(\\s*(ELSE)%1)" )
            .arg( str_rx_proc );

    str_rx_SELECT = QString( "(%1|%2|%3)" )
            .arg( str_rx_SELECT_start )
            .arg( str_rx_SELECT_mid )
            .arg( str_rx_SELECT_end );
    /// FOR 指令
    str_rx_FOR = QString( "(\\s*(FOR)\\s*%1=%2%3(%4))" )
            .arg( str_rx_R_i )
            .arg( str_rx_ri_tmp1 )
            .arg( str_rx_opt_DOWNTO_TO )
            .arg( str_rx_ri_tmp1 );
    /// ENDFOR 指令
    str_rx_ENDFOR = "(\\s*(ENDFOR)\\s*)";

    /*****************************
     *日期：2017年３月２日
     * 修改人：ｓｔｅｖｅｎ
     * 修改内容：添加新的ｍｏｔｉｏｎ指令匹配
     * ***************************/
    str_rx_MSKIP =  "\\s*(DI)?\\s*(\\[?)\\s*([GP]?\\s*\\d*\\:?\\s*[R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)\\s*\\=?\\s*([ONFF]{2,3})?\\s*(Skip)?\\s*(,)?\\s*(LBL)?\\s*(\\[?)\\s*([R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)";
    str_rx_MADD1 = "\\s*(Wjnt)?\\s*(INC)?\\s*(ACC)?\\s*(\\d*)\\s*([EV]{0,2})\\s*(\\d*)\\s*\\%?\\s*(PTH)?";
    str_rx_MADD2 = "\\s*(Offset)?\\s*([PR]{0,2})\\s*(\\[?)\\s*([GP]{0,2}\\s*\\d*\\:?\\s*[R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)\\s*(Tool_Offset)?\\s*([PR]{0,2})\\s*(\\[?)\\s*([GP]?\\s*\\d*\\:?\\s*[R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)";

    str_rx_MOTION_P_JLA = "\\s*([JLA])\\s*@?\\s*([PAL]+_?\\d*)\\s*\\[([ARBTM]*_?\\d*)\\s*:?\\s*\\w*\\s*\\w*\\]\\s*(\\d+\\.?\\d*\\%?[a-z]*\\/?[a-z]*)\\s\\s*([FINECT]{0,4})\\s*(\\d*)";
    str_rx_MOTION_P_C2 = "\\s*@?\\s*([P])\\[(\\[?\\d+\\]?)\\s*:?\\s*\\w*\\s*\\w*\\]\\s*(\\d+\\.?\\d*\\%?[a-z]*\\/?[a-z]*)\\s\\s*([FINECT]{0,4})\\s*(\\d*)";
    str_rx_MOTION_P_C1 = "\\s*([C])\\s*@?\\s*([P])\\[(\\[?\\d+\\]?)\\]";


    str_rx_MOTION_BASE_JLA = "\\s*([JLA])\\s*@?\\s*([PRAL]+_?\\d*)\\s*\\[([ARBTM]*\\[?_?\\d*\\]?)\\s*:?\\s*\\w*\\s*\\w*\\]\\s*(\\d+\\.?\\d*\\%?[a-z]*\\/?[a-z]*)\\s\\s*([FINECT]{0,4})\\s*(\\d*)";
    str_rx_MOTION_BASE_C2 =  "\\s*@?\\s*([P][R]?)\\[([R]*\\[?\\d+\\]?)\\s*:?\\s*\\w*\\s*\\w*\\]\\s*(\\d+\\.?\\d*\\%?[a-z]*\\/?[a-z]*)\\s\\s*([FINECT]{0,4})\\s*(\\d*)";
    str_rx_MOTION_BASE_C1 = "\\s*([C])\\s*@?\\s*([P][R]?)\\[([R]*\\[?\\d+\\]?)\\]";

    str_rx_MOTION_JLA = QString("%1%2%3").arg(str_rx_MOTION_P_JLA).arg(str_rx_MADD1).arg(srt_rx_notes);
    str_rx_MOTION_C2 = QString("%1%2%3").arg(str_rx_MOTION_P_C2).arg(str_rx_MADD1).arg(srt_rx_notes);
    str_rx_MOTION_C1 = QString("%1%2").arg(str_rx_MOTION_P_C1).arg(srt_rx_notes);
    str_rx_MOTION_JLCA = QString("(%1|%2|%3)").arg(str_rx_MOTION_JLA).arg(str_rx_MOTION_C1).arg(str_rx_MOTION_C2);


    str_rx_MOTION_SKIP_JL = QString("%1%2%3%4%5").arg(str_rx_MOTION_BASE_JLA).arg(str_rx_MSKIP).arg(str_rx_MADD1).arg(str_rx_MADD2).arg(srt_rx_notes);
    str_rx_MOTION_SKIP_C = QString("%1%2%3%4%5").arg(str_rx_MOTION_BASE_C2).arg(str_rx_MSKIP).arg(str_rx_MADD1).arg(str_rx_MADD2).arg(srt_rx_notes);
    str_rx_MOTION_SKIP_JLC = QString("(%1|%2)").arg(str_rx_MOTION_SKIP_JL).arg(str_rx_MOTION_SKIP_C);

    str_rx_pause = QString("%1%2").arg("\\s*(PAUSE)").arg(srt_rx_notes);
    str_rx_abort = QString("%1%2").arg("\\s*(ABORT)").arg(srt_rx_notes);
    str_rx_end = QString("%1%2").arg("\\s*(END)").arg(srt_rx_notes);

    str_rx_ualm = QString("%1%2").arg("\\s*(UALM)\\s*(\\[)\\s*(.*)\\s*(\\])").arg(srt_rx_notes);
    str_rx_message = QString("%1%2").arg("\\s*(MESSAGE)\\s*(\\[)\\s*(.*)\\s*(\\])").arg(srt_rx_notes);
    str_rx_override = QString("%1%2").arg("\\s*(OVERRIDE)\\s*=\\s*([AR]*\\[?\\d*\\]?)\\s*(%)").arg(srt_rx_notes);

    str_rx_timer_cmd = "\\s*(TIMER)\\s*(\\[\\d+\\])\\s*=\\s*([STARTOPE]{4,5})";
    str_rx_timer_value = "\\s*(TIMER)\\s*(\\[\\d+\\])\\s*=(.*)";
    str_rx_timer = QString("%1|%2").arg(str_rx_timer_cmd).arg(str_rx_timer_value);

    str_rx_rsr = QString("%1%2").arg("\\s*(RSR\\s*\\[\\d+\\])\\s*=\\s*([ENABLEDIS]{6,7})").arg(srt_rx_notes);


    //----------------------------------------------------------------------------------复杂匹配表达式
    str_rx_gripper_active =  QString("%1%2").arg("\\s*(ActiveGripper)\\s*(,)\\s*(LBL)\\s*\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]").arg(srt_rx_notes);
    str_rx_gripper_set = QString("%1%2").arg("\\s*(SetGripper)\\s*(\\d+)\\s*(\\d+)\\s*(\\d+)").arg(srt_rx_notes);
    str_rx_gripper_wait = QString("%1%2").arg("\\s*(WaitGripper)\\s*(,)\\s*(TIMEOUT)\\s*(\\d+\\.?\\d*)\\s*(LBL)\\s*\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]").arg(srt_rx_notes);

//    vague_str_gripper_active = "\\s*(ActiveGripper)\\s*(,)\\s*(LBL)\\s*\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*";
//    vague_str_gripper_set = "\\s*(SetGripper)\\s*(\\d+)\\s*(\\d+)\\s*(\\d+)\\s*";
//    vague_str_gripper_wait = "\\s*(WaitGripper)\\s*(,)\\s*(TIMEOUT)\\s*(\\d+\\.?\\d*)\\s*(LBL)\\s*\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*";
//    vague_str_gripper = QString("%1|%2|%3")

    /****************************************
     *
     * 时间：2018-6-1
     * 修改人:hualei
     * 添加内容: MODBUS_START、MODBUS_READ、MODBUS_WRITE 指令匹配
     *
     * *************************************/
    str_rx_modbusStart = QString("%1%2%3%4")
                         .arg("\\s*(MODBUS_START)\\s*(,)\\s*")
                         .arg("(\\-?\\d+)\\s*(,)\\s*")
                         .arg("(.*)\\s*(,)\\s*(.*)\\s*(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
                         .arg("(//)\\s*(.*)");

//    str_rx_modbusRead = QString("%1%2%3%4%5%6")
//                        .arg("\\s*(MODBUS_READ)\\s*(,)\\s*")
//                        .arg("(R\\[(\\-?\\d+)\\])\\s*(,)\\s*")
//                        .arg("(.*)\\s*(,)\\s*")
//                        .arg("(\\-?\\d+)\\s*(,)\\s*")
//                        .arg("(.*)\\s*(,)\\s*(.*)\\s*(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
//                        .arg("(//)\\s*(.*)");
//    str_rx_modbusRead = QString("%1%2%3%4%5%6")
//                            .arg("\\s*(MODBUS_READ)\\s*,\\s*")
//                            .arg("(R\\[(\\-?\\d+)\\])\\s*,\\s*")
//                            .arg("(\\-?\\d+)\\s*,\\s*")
//                            .arg("(\\-?\\d+)\\s*,\\s*")
//                            .arg("(INTERNET|RS485)\\s*,\\s*(MASTER|SLAVE)\\s*,\\s*(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
//                            .arg("(//)\\s*(.*)");
    str_rx_modbusRead = QString("%1%2%3%4%5%6")
                            .arg("\\s*(MODBUS_READ)\\s*,\\s*")
                            .arg("(R\\[(\\-?\\d+)\\])\\s*,\\s*")
                            .arg("(\\-?\\d+)\\s*,\\s*")
                            .arg("(.*)\\s*,\\s*")
                            .arg("(INTERNET|RS485)\\s*,\\s*(MASTER|SLAVE)\\s*,\\s*(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
                            .arg("(//)\\s*(.*)");

//    str_rx_modbusWrite = QString("%1%2%3%4%5%6")
//                        .arg("\\s*(MODBUS_WRITE)\\s*(,)\\s*")
//                        .arg("((\\-?\\d+)|(R\\[(\\-?\\d+)\\]))\\s*(,)\\s*")
//                        .arg("(.*)\\s*(,)\\s*")
//                        .arg("(\\-?\\d+)\\s*(,)\\s*")
//                        .arg("(.*)\\s*(,)\\s*(.*)\\s*(,)\\s*(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
//                        .arg("(//)\\s*(.*)");
    str_rx_modbusWrite = QString("%1%2%3%4%5%6")
            .arg("\\s*(MODBUS_WRITE)\\s*,\\s*")
            .arg("((\\-?\\d+)|(R\\[(\\-?\\d+)\\]))\\s*,\\s*")
            .arg("(\\-?\\d+)\\s*,\\s*")
            .arg("(.*)\\s*,\\s*")
            .arg("(INTERNET|RS485)\\s*,\\s*(MASTER|SLAVE)\\s*,\\s*(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
            .arg("(//)\\s*(.*)");

    /*******************************************
     * 日期：2018年6月8日
     * 修改人：hualei
     * 修改内容:添加 MOVE_MAG、MODBUS_FREE 指令匹配
     *
     * *****************************************/
     str_rx_moveMag = QString("%1%2%3%4%5")
                     .arg("\\s*(MOVE_MAG)\\s*")
                     .arg("(L|M|R)\\s*(FRONT|BACK)\\s*(0|100|[0-9]{1,2})(%)\\s*(,)\\s*")
                     .arg("(RFID)\\s*(\\-?\\d+)\\s*")
                     .arg("(\\s|,(RFID_STOP)|,(MAG_STOP)|,(INPUT\\s*(\\-?\\d+)))\\s*")
                     .arg("(//)\\s*(.*)");

     /*******************************************
      * 日期：2018年10月26日
      * 修改人：丁培
      * 修改内容:添加 .arg("\\s*((DET)|(NODET))\\s*,") 指令匹配　探测障碍
      * //指令正则表达式涉及ｈｍｉ的　programcheck.cpp文件进行语法检查，
      * 同时涉及到ProgramDelegate::analysisＸＸＸＸInstruction(),
      * 还涉及到MoveFreeInstructionDelegate::recordDPointSlot(int recordType)
      * 还涉及到ProgramDelegate::guidanceMoveFreeSlot()
      * *****************************************/

    str_rx_moveFree = QString("%1%2%3%4%5%6%7%8%9%10%11%12")
            .arg("\\s*(MOVE_FREE)")
            .arg("\\s*(DP|DPR|DPL)\\[(.*)\\]")
            .arg("\\s*(0|100|[0-9]{1,2})%\\s*,")
            .arg("\\s*(WHEEL|IMU|LASER)\\s*,")
            .arg("\\s*((CNT(\\d+))|FINE)\\s*,(AUTO|LINE|SPLINE|ROTATE)\\s*,")
            .arg("\\s*(P|N)\\s*,")
            .arg("\\s*((\\-?\\d+)(\\.\\d+)?)\\s*,")
            .arg("\\s*(CU1|OP|QR\\[(\\d+)\\]|VMark\\[(\\d+)\\])\\s*,")
            .arg("\\s*(Laser\\[(\\d+)\\])\\s*,")
            .arg("\\s*((DET(\\d*))|(NODET))\\s*,")
            .arg("\\s*(JMP\\s*LB\\[(\\d+)\\])\\s*")
            .arg(".*(//)\\s*(.*)");// \\s*(//)\\s*(.*)

    /*******************************************
     * 日期：2018年11月30日
     * 修改人：丁培
     * 修改内容:添加 .arg("\\s*((DET)|(NODET))\\s*,") 指令匹配　呼叫等待
     * *****************************************/
   str_rx_waitCommand = QString("%1%2%3%4")
           .arg("\\s*(WAIT_COMMAND)")
           .arg("\\s*(R)\\[(\\d+)\\]\\s*,")
           .arg("\\s*(TIMEOUT)\\s*(\\d+)\\s*,")
           .arg("\\s*(JMP)\\s*(LBL\\[(\\w+)\\])\\s*(.*)");
    /*****************************************************
     * 修改时间：    2018-09-05
     * 修改人：        hualei
     * 修改内容：   添加TCP以太网通信指令正则表达式字符串
     * ***************************************************/
    str_rx_tcpStart = QString("%1%2%3%4%5%6")
            .arg("\\s*(TCP_START)\\s*")
            .arg("((\\-?\\d+)\\.(\\-?\\d+)\\.(\\-?\\d+)\\.(\\-?\\d+))\\s*(,)\\s*")
            .arg("(\\-?\\d+)\\s*(,)")
            .arg("(SERVER|CLIENT)\\s*(,)\\s*")
            .arg("(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
            .arg("(//)\\s*(.*)");

    str_rx_tcpRead = QString("%1%2%3%4%5%6%7%8")
            .arg("\\s*(TCP_READ)\\s*")
            .arg("(R\\[(\\-?\\d+)\\])\\s*,\\s*")
            .arg("(R\\[(\\-?\\d+)\\])\\s*,\\s*")
            .arg("((\\-?\\d+)\\.(\\-?\\d+)\\.(\\-?\\d+)\\.(\\-?\\d+))\\s*,\\s*")
            .arg("(\\-?\\d+)\\s*,\\s*")
            .arg("(SERVER|CLIENT)\\s*,\\s*")
            .arg("(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
            .arg("(//)\\s*(.*)");

    str_rx_tcpWrite = QString("%1%2%3%4%5%6%7%8")
            .arg("\\s*(TCP_WRITE)\\s*")
            .arg("((R\\[(\\-?\\d+)\\])|(\\-?\\d+))\\s*")
            .arg("((,R\\[(\\-?\\d+)\\]\\s*,)|(,))\\s*")
            .arg("((\\-?\\d+)\\.(\\-?\\d+)\\.(\\-?\\d+)\\.(\\-?\\d+))\\s*,\\s*")
            .arg("(\\-?\\d+)\\s*,\\s*")
            .arg("(SERVER|CLIENT)\\s*,\\s*")
            .arg("(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
            .arg("(//)\\s*(.*)");

    // MUSIC
    str_rx_music = QString("%1%2%3%4%5")
            .arg("\\s*(MUSIC)")
            .arg("\\s*([\\s\\S]*)\\s*,")
            .arg("\\s*([1-6]|循环|暂停)\\s*,")
            .arg("\\s*(0|[0-9]{1,2}|100)")
            .arg("\\s*(//)\\s*([\\s\\S]*)");

    // SET_ODOM
    str_rx_setOdom = QString("%1%2%3%4%5")
            .arg("\\s*(SET_ODOM)")
            .arg(QString("%1%2").arg(str_rx_float).arg(","))
            .arg(QString("%1%2").arg(str_rx_float).arg(","))
            .arg(str_rx_float)
            .arg("(//)\\s*(.*)");

    // CHARGING
    str_rx_charging = QString("%1%2%3%4")
            .arg("CHARGING\\s*")
            .arg("(TIME|CAPARITY|FIRFIN)\\s*,\\s*")
            .arg("((\\d+)|((\\d+),(\\d+)))\\s*")
            .arg("(//)\\s*(.*)");

    // LIFT
    str_rx_liftMechanism = QString("%1%2%3%4%5%6")
            .arg("(LIFT)\\s*")
            .arg("(General|Heavy),\\s*")
            .arg("(RISE|DOWN|RIMI|DOMI),\\s*")
            .arg("(\\-?\\d+),\\s*")
            .arg("(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
            .arg("(//)\\s*(.*)");

    str_rx_loadMap = QString("%1%2%3%4")
            .arg("\\s*(LOAD_MAP)\\s*")
            .arg("\\s*(.*),\\s*")
            .arg("\\s*(JMP\\s*LB\\[(\\d+)\\])\\s*")
            .arg("\\s*(//)\\s*(.*)");

    str_rx_checkBattery=QString("%1%2%3")
            .arg("\\s*(CHECK_BATTERY)\\s*")
            .arg("\\s*([-]?(\\d+))\\s*[,]\\s*")
            .arg("\\s*(LBL)\\s*\\[(\\w+)\\].*//(.*)");

    // ROBOT_MOVE机械手控制
    str_rx_RobotMove = QString("%1%2%3%4%5%6%7%8")
            .arg("\\s*(ROBOT_MOVE)")
            .arg("\\s*(IP\\[(.*)\\])\\s*,")
            .arg("\\s*(PORT\\[(\\d+)\\])\\s*,")
            .arg("\\s*(SERVER|CLIENT)\\s*,")
            .arg("\\s*SEND\\[(.*)\\]\\s*,")
            .arg("\\s*WAIT\\[(.*)\\]\\s*,")
            .arg("\\s*(TIMEOUT)\\s*(\\d+)\\s*,")
            .arg("\\s*(JMP)\\s*(LBL\\[(\\w+)\\])\\s*//(.*)");

    str_rx_Roller = QString("%1%2%3%4%5%6")
            .arg("(ROLLER)\\s*")
            .arg("(General|Heavy),\\s*")
            .arg("(P|R|A|B),\\s*")
            .arg("(\\-?\\d+),\\s*")
            .arg("(JMP)\\s*(LB\\[(\\-?\\d+)\\])\\s*")
            .arg("(//)\\s*(.*)");
}

int ProgramRegExp::analysisAcc(QString programStr, int &accOut)
{
    QRegExp rx("[\\s|\\S]*ACC(\\d*)[\\s|\\S]*");

    bool isMatch=rx.exactMatch(programStr);
//        qDebug()<<rx;

    if(false==isMatch )
    {
        return 0;
    }
    else
    {
        accOut=rx.cap(1).toInt();
        return 1;
    }
}

int ProgramRegExp::analysisOffsetPr(QString programStr, QString &prIndexOut)
{

        QRegExp rx("[\\s|\\S]*Offset,PR\\[(\\d*)\\][\\s|\\S]*");

        bool isMatch=rx.exactMatch(programStr);
//        qDebug()<<rx;

        if(false==isMatch )
        {
            return 0;;
        }
        else
        {
            prIndexOut=rx.cap(1);
            return 1;
        }
}



int ProgramRegExp::patExtractInstructionType(QString programStr)
{

    return simpleCheck->patExtractInstructionType(programStr);

}


/*****************字符串处理函数***********************/
int ProgramRegExp::strToInt(QString in)
{
    QString tmp;
    for(int j = 0; j < in.length(); j++)
    {
        if(in[j] >= '0' && in[j] <= '9')
            tmp.append(in[j]);
    }
    bool ok;
    int tar=tmp.toInt(&ok,10); // ok=rue
    return tar;
}

double ProgramRegExp::strToDouble (QString in)
{
//    QString tmp;
//    for(int j = 0; j < in.length(); j++)
//    {
//        if((in[j] >= '0' && in[j] <= '9')||in[j]=='.'||in[j]=='-')
//            tmp.append(in[j]);
//    }
//    bool ok;
//    double tar=tmp.toDouble(&ok); // ok=rue
//    return tar;

    return in.toDouble();
}

double ProgramRegExp::strCharsToDouble(QString in)
{
    QString tmp;
    for(int j = 0; j < in.length(); j++)
    {
        if((in[j] >= '0' && in[j] <= '9')||in[j]=='.'||in[j]=='-')
            tmp.append(in[j]);
    }
    bool ok;
    double tar=tmp.toDouble(&ok); // ok=rue
    return tar;
}

QString ProgramRegExp::strFilt(QString in)
{
    QString tmp;
    for(int j = 0; j < in.length(); j++)
    {
        if((in[j] >= 'a' && in[j] <= 'z') || (in[j] >= 'A' && in[j] <= 'Z')||in[j]=='['||in[j]==']'||in[j] =='%'||in[j] == '/')
            tmp.append(in[j]);
    }
    return tmp;
}

int ProgramRegExp::patAxisMove(QString programStr, Line &lineOut)
{
    lineOut.type = INS_AXIS_MOVE;
    QString pattern = QString("%1%2%3%4")
            .arg("\\s*(AXISMOVE)\\s*(AXIS?)\\s*\\[\\s*(\\d*\\s*\\:?)\\s*([R]?\\s*\\[?\\s*\\d*\\s*\\]?\\w*)\\s*\\]\\s*(\\d*\\.?\\d*)\\s*(\\%?[a-z]*\\/?[a-z]*)")
            .arg("\\s*(TARGET)\\s*(.*)")
            .arg("\\s*(CARREFERENCE|MAPREFERENCE|ABSOLUTE|INC|FOLLOW)\\s*")
            .arg(".*(//)\\s*(.*)");// \\s*(//)\\s*(.*)

    QRegExp rx2(pattern);
    programStr.indexOf(rx2);
    QString tmpId=rx2.cap(3) + rx2.cap(4);
    lineOut.axisMove.axisId= tmpId.toInt();
    lineOut.axisMove.velocityRatio = rx2.cap(5).toFloat();
    if("%" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_PERCENT;
    }
    else if("mm/sec" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_MM_SEC;
    }
    else if("cm/min" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_CM_MIN;
    }
    else if("deg/sec" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_DEG_SEC;
    }
    else if("sec" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_SEC;
    }
    else if("msec" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_MSEC;
    }
    else if("inch/min" == rx2.cap(6))
    {
        lineOut.axisMove.rateUnitTypeFlag = E_RATE_INCH_MIN;
    }
    qDebug()<<rx2.cap(7);
    qDebug()<<rx2.cap(8);
    lineOut.axisMove.targetPosition = rx2.cap(8).toDouble();
    QString tmpReference=rx2.cap(9);
    if("CARREFERENCE"==tmpReference)
    {
        lineOut.axisMove.positionReference=E_POSITION_REFERENCE_CAR;
    }
    else if("FOLLOW"==tmpReference)
    {
        lineOut.axisMove.positionReference=E_POSITION_REFERENCE_FOLLOW;
    }
    else if("MAPREFERENCE"==tmpReference)
    {
        lineOut.axisMove.positionReference=E_POSITION_REFERENCE_MAP;
    }
    else if("ABSOLUTE"==tmpReference)
    {
        lineOut.axisMove.positionReference=E_POSITION_REFERENCE_ABSOLUTE;
    }
    else if("INC"==tmpReference)
    {
        lineOut.axisMove.positionReference=E_POSITION_REFERENCE_INC;
    }
    else
    {
        lineOut.axisMove.positionReference=E_POSITION_REFERENCE_ERROR;
        return -1;
    }
//    qDebug()<<rx2.cap(9);
//    qDebug()<<lineOut.axisMove.targetPosition;
    return 1;


}

int ProgramRegExp::patMotion(QString programStr, QString forwardLineString, Line &lineOut)
{

    //
    lineOut.type = MOTION;
    //
    //************************************
    /**
     * @brief instructionMainFlag   分类:属于_NORMAL还是_STAMP
     */
    int instructionMainFlag;
    /**
     * @brief instructionTypeFlag   指令类型选择标志　1:J  2:L  3:C  4:A
     */
    MOTION_FORMAT instructionTypeFlag;

    //************************************
    /**
     * @brief instructionPosition   指令位置
     */
    QString instructionPosition;
    /**
     * @brief positionTypeFlag      指令位置类型　0:P  1:PR
     */
    POSITION_FORMAT positionTypeFlag;
    /**
     * @brief positionIndex         指令位置下标
     */
    QString pointIndexStr;


    //************************************
    /**
     * @brief instructionRate       指令速度
     */
    float instructionRate;

    /**
     * @brief rateUnitTypeFlag      速度单位类型
     *
     *   0:%  1:mm/sec  2:cm/min  3:deg/sec  4:sec  5:msec  6:inch/min
     */
    FEED_RATE_FORMAT rateUnitTypeFlag;

    /**
     * @brief fixedPositionTypeFlag　定位类型标志　０：FINE　１：CNT
     */
    CNT_FORMAT fixedPositionTypeFlag;
    /**
     * @brief cntValue              CNT数值
     */
    int cntValue;

    //************************************
    /**
     * @brief note                  指令注释
     */
    QString note;


    /**
     * @brief diFlag                DI选择标志　MOTION_DI_OFF,MOTION_DI_ON,MOTION_DI_NONE
     */
    MOTION_DI_TYPE diFlag;
    /**
     * @brief diIndex               DI索引号
     */
    QString diIndex;
    /**
     * @brief labelIndex            跳转标签号
     */
    QString labelIndex;

    /**
     * @brief wjntFlag              Wjnt指令添加标志　0:未选中  1: 选中
     */
    MOTION_WJNT_TYPE wjntFlag;
    /**
     * @brief incFlag               INC指令添加标志　0:未选中  1: 选中
     */
    MOTION_INC_TYPE incFlag;
    /**
     * @brief accFlag               ACC指令添加标志　0:未选中  1: 选中
     */
    int accFlag;
    /**
     * @brief offsetFlag            Offset指令添加标志　0:未选中  1: 选中
     */
    int offsetFlag;
    /**
     * @brief toolOffsetFlag        Tool_Offset指令添加标志　0:未选中  1: 选中
     */
    int toolOffsetFlag;
    /**
     * @brief evFlag                EV指令添加标志　0:未选中  1: 选中
     */
    int evFlag;
    /**
     * @brief pthFlag               PTH指令添加标志　0:未选中  1: 选中
     */
    MOTION_PTH_TYPE pthFlag;

    /**
     * @brief accValue              ACC加减速倍率值
     */
    int accValue;

    /**
     * @brief offsetPrIndex         Offset指令位置下标
     */
    QString offsetPrIndex;

    /**
     * @brief toolOffsetPrIndex     Tool_Offset位置下标
     */
    QString toolOffsetPrIndex;

    /**
     * @brief eValue                EV附加轴移动最大速度比率
     */
    int evValue;


    QRegExp rx_currentLine("^\\s*([A-Z_]*)\\-?\\s*([BEXND]{0,3})\\s*\\_?\\d*\\s*([PAL]{0,3})\\s*(.*)");
    QRegExp rx_forward("\\s*([A-Z_]*)\\s+(.*)");

    programStr.indexOf(rx_currentLine);
    forwardLineString.indexOf(rx_forward);

    //QString pattern("\\s*([JLCA]?)\\s*([P][R]?)\\s*\\[\\s*(\\d*\\s*\\:?)\\s*([R]?\\s*\\[?\\s*\\d*\\s*\\]?\\w*)\\s*\\]\\s*(\\d*\\.?\\d*)\\s*(\\%?[a-z]*\\/?[a-z]*)\\s*([FINECT]{0,4})\\s*(\\d*)\\s*(.*)");
    QString pattern("\\s*([JLCA]?)\\s*([PRAL_\\d]{1,5})\\s*\\[\\s*(\\d*\\s*\\:?)\\s*([R]?\\s*\\[?\\s*\\d*\\s*\\]?\\w*)\\s*\\]\\s*(\\d*\\.?\\d*)\\s*(\\%?[a-z]*\\/?[a-z]*)\\s*([FINECT]{0,4})\\s*(\\d*)\\s*.*(//)(.*)");
    QRegExp rx_mainInfo (pattern);
    // \s*([DI]{0,2})\s*(\[?)\s*([GP]{0,2}\s*\d*\:?\s*[R]?\s*\[?\s*\d*)\s*(\]?)\s*(\]?)\s*\=?\s*([ONF]{0,3})\s*([SkipLB,]*)\s*([LBL]{3})\[([R]?\[?\S+\]?)\s*:?\s*([^:]{0,16})\].*(//)\s*(.*)
    QString pattern2("\\s*([DI]{0,2})\\s*(\\[?)\\s*([GP]{0,2}\\s*\\d*\\:?\\s*[R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)\\s*\\=?\\s*([ONF]{0,3})\\s*([SkipLB,]*)\\s*([LBL]{3})\\[([R]?\\[?\\S+\\]?)\\s*:?\\s*([^:]{0,16})\\].*(//)\\s*(.*)");
    QRegExp rx_di(pattern2);
    QString pattern3("\\s*([Wjnt]{0,4})\\s*([INC]{0,3})\\s*([A]?[C]?[C]?)\\s*(\\d*)\\s*([EV]{0,2})\\s*(\\d*)\\s*(\\%?)\\s*([PTH]{0,3})\\s*(.*)");
    QRegExp rx_wjnt(pattern3);
    QString pattern4("\\s*([Offset,]{0,7})\\s*([PR]{0,2})\\s*(\\[?)\\s*([GP]{0,2}\\s*\\d*\\:?\\s*[R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)\\s*(.*)");
    QRegExp rx_offset(pattern4);
    QString pattern5("\\s*([Tool_Offset,]{0,12})\\s*([PR]{0,2})\\s*(\\[?)\\s*([GP]{0,2}\\s*\\d*\\:?\\s*[R]?\\s*\\[?\\s*\\d*)\\s*(\\]?)\\s*(\\]?)\\s*[\\/\\;\\s]*\\s*([\\w\\s\\(\\)\\.]*)");
    QRegExp rx_tool_offset(pattern5);
    programStr.indexOf(rx_mainInfo);
    if(D_DEBUG_FLAG)
    {
        qDebug()<<"rx_mainInfo"<<rx_mainInfo.capturedTexts();

    }
    rx_mainInfo.cap(9).indexOf(rx_di);
    if(D_DEBUG_FLAG)
    {
        qDebug()<<"rx_di"<<rx_di.capturedTexts();

    }
    rx_di.cap(12).indexOf(rx_wjnt);
    if(D_DEBUG_FLAG)
    {
        qDebug()<<"rx_wjnt"<<rx_wjnt.capturedTexts();
    }
    rx_wjnt.cap(9).indexOf(rx_offset);
    if(D_DEBUG_FLAG)
    {
        qDebug()<<"rx_offset"<<rx_offset.capturedTexts();
    }
    rx_offset.cap(7).indexOf(rx_tool_offset);
    if(D_DEBUG_FLAG)
    {
        qDebug()<<"rx_tool_offset"<<rx_tool_offset.capturedTexts();
    }

    QRegExp rx_circule("\\s*([C])\\s*([P][R]?)\\s*\\[\\s*(\\d*\\s*\\:?)\\s*([R]?\\s*\\[?\\s*\\d*\\s*\\]?\\w*)\\s*\\](.*)");
    programStr.indexOf(rx_circule);

    if(D_DEBUG_FLAG)
    {
        qDebug()<<"rx_offset"<<rx_offset.capturedTexts();
    }

    instructionMainFlag = EM_INSTRUCTION_NORMAL;//2017.05.16补充
    if("J" == rx_currentLine.cap(1))
    {
        instructionTypeFlag = E_MOTION_J;
    }
    else if("L" == rx_currentLine.cap(1))
    {
        instructionTypeFlag = E_MOTION_L;
    }
    else if("C" == rx_forward.cap(1))
    {
        instructionTypeFlag = E_MOTION_C2;
    }
    else if("A" == rx_currentLine.cap(1))
    {
        instructionTypeFlag = E_MOTION_A;
    }
    else if("C" == rx_currentLine.cap(1))
    {
        instructionTypeFlag = E_MOTION_C;
    }
    else
    {
        return -1;
    }

    instructionPosition = rx_mainInfo.cap(2);
    lineOut.motion.palNum=1;
    if("P" == rx_mainInfo.cap(2))
    {
        positionTypeFlag = E_POSITION_P;
        pointIndexStr = rx_mainInfo.cap(3) + rx_mainInfo.cap(4);
    }
    else if("PR" == rx_mainInfo.cap(2))
    {
        positionTypeFlag = E_POSITION_PR;
        pointIndexStr = rx_mainInfo.cap(3) + rx_mainInfo.cap(4);
    }
    else
    {
        QRegExp rx_palIndexInfo("PAL_(\\d*)");
        rx_mainInfo.cap(2).indexOf(rx_palIndexInfo);
        QRegExp rx_palPointInfo("([ARBTM_]{2,3})(\\d*)");
        QString tmpPointStr=rx_mainInfo.cap(3) + rx_mainInfo.cap(4);
        tmpPointStr.indexOf(rx_palPointInfo);
        //提取码跺号
        lineOut.motion.palNum=rx_palIndexInfo.cap(1).toInt();
        //提取点类型
        if("A_"==rx_palPointInfo.cap(1))
        {
            positionTypeFlag = E_POSITION_PAL_A;
        }
        else if("R_"==rx_palPointInfo.cap(1))
        {
            positionTypeFlag = E_POSITION_PAL_R;
        }
        else
        {
            positionTypeFlag = E_POSITION_PAL_BTM;
        }
        //提取点号
        pointIndexStr = rx_palPointInfo.cap(2);

        if(D_DEBUG_FLAG)
        {
            qDebug()<<"rx_palIndexInfo"<<rx_palIndexInfo.capturedTexts()
                      <<"rx_palPointInfo"<<rx_palPointInfo.capturedTexts();
        }
    }



    instructionRate = rx_mainInfo.cap(5).toFloat();
    if("%" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_PERCENT;
    }
    else if("mm/sec" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_MM_SEC;
    }
    else if("cm/min" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_CM_MIN;
    }
    else if("deg/sec" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_DEG_SEC;
    }
    else if("sec" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_SEC;
    }
    else if("msec" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_MSEC;
    }
    else if("inch/min" == rx_mainInfo.cap(6))
    {
        rateUnitTypeFlag = E_RATE_INCH_MIN;
    }

    if("FINE" == rx_mainInfo.cap(7))
    {
        fixedPositionTypeFlag = FINE;
        cntValue =0;
    }
    else
    {
        fixedPositionTypeFlag = CNT;
        cntValue = rx_mainInfo.cap(8).toInt();
    }

    lineOut.motion.comment=rx_mainInfo.cap(10);

    if("DI" == rx_di.cap(1))
    {
        diIndex = rx_di.cap(3) + rx_di.cap(5);
        if("ON" == rx_di.cap(6))
        {
            diFlag = MOTION_DI_ON;
        }
        else
        {
            diFlag = MOTION_DI_OFF;
        }
        labelIndex = rx_di.cap(9);
    }
    else
    {
        diFlag = MOTION_DI_NONE;
    }
    if("Wjnt" == rx_wjnt.cap(1))
    {
        wjntFlag = MOTION_WJNT_EXIST;
    }
    else
    {
        wjntFlag = MOTION_WJNT_NONEXIST;
    }
    if(("INC" == rx_wjnt.cap(2)) || ("C" == rx_wjnt.cap(2)))
    {
        incFlag = MOTION_INC_EXIST;
    }
    else
    {
        incFlag = MOTION_INC_NONEXIST;
    }
//    if("ACC" == rx4.cap(3))
//    {
//        accFlag = 1;
//        accValue = rx4.cap(4).toInt();
//    }
//    else
//    {
//        accFlag = 0;
//    }

    if(1==analysisAcc(programStr,accValue))
    {
        accFlag = 1;
    }
    else
    {
        accFlag = 0;
        accValue=-1;
    }

    if("EV" == rx_wjnt.cap(5))
    {
        evFlag = 1;
        evValue = rx_wjnt.cap(6).toInt();
    }
    else
    {
        evFlag = 0;
    }
    if("PTH" == rx_wjnt.cap(8))
    {
        pthFlag = MOTION_PTH_EXIST;
    }
    else
    {
        pthFlag = MOTION_PTH_NONEXIST;
    }


    if(1==analysisOffsetPr(programStr,offsetPrIndex))
    {
        offsetFlag = 1;
    }
    else
    {
        offsetFlag = 0;
    }
//    if(("Offset" == rx5.cap(1)) || ("ffset") == rx5.cap(1))
//    {
//        offsetFlag = 1;
//        offsetPrIndex = rx5.cap(4) + rx5.cap(6);
//    }
//    else
//    {
//        offsetFlag = 0;
//    }
    if(("Tool_Offset" == rx_tool_offset.cap(1)) || ("ool_Offset" == rx_tool_offset.cap(1)))
    {
        toolOffsetFlag = 1;
        toolOffsetPrIndex = rx_tool_offset.cap(4) + rx_tool_offset.cap(6);
    }
    else
    {
        toolOffsetFlag = 0;
    }

    note = rx_tool_offset.cap(7);

    if("C" == rx_currentLine.cap(1))
    {
        instructionTypeFlag = E_MOTION_C;
        instructionPosition = rx_circule.cap(2);
        if("P" == rx_circule.cap(2))
        {
            positionTypeFlag = E_POSITION_P;
        }
        else if("PR" == rx_circule.cap(2))
        {
            positionTypeFlag = E_POSITION_PR;
        }
        pointIndexStr = rx_circule.cap(3) + rx_circule.cap(4);
    }


    /**
     * @brief motionFormat          运动指令类型J，L，C，A
     */
    lineOut.motion.motionFormat=instructionTypeFlag;
    /**
     * @brief rateFormat           运动速度单位 PERCENT,MM_SEC,CM_MIN
     */
    lineOut.motion.rateFormat=rateUnitTypeFlag;
    /**
     * @brief positionFormat        点位信息存储P【】，PR【】
     */
    lineOut.motion.positionFormat=positionTypeFlag;
    /**
     * @brief cntFormat             CNT格式，CNT或者FINE
     */
    lineOut.motion.cntFormat=fixedPositionTypeFlag;


    /**
     * @brief p                     点号
     */
    lineOut.motion.p=pointIndexStr.toInt();
    /**
     * @brief rate                  速率
     */
    lineOut.motion.rate=instructionRate;
    /**
     * @brief cnt                   平滑度cnt
     */
    lineOut.motion.cnt=cntValue;
    /**
     * @brief acc
     */
    lineOut.motion.acc=accValue;
    /**
     * @brief smoothFlag            平滑标志
     */
    lineOut.motion.smoothFlag=SMOOTHING_NONE;

    /**
     * @brief endFlag               平滑规划的结束标志，当遇到for，jump时就会添加endFlag
     */
    lineOut.motion.endFlag=0;
    /**
     * @brief circleFlag            圆弧标志
     */
    lineOut.motion.circleFlag=CIRCLE_NONE;

    lineOut.motion.pointType=DIRECT;//暂时不支持其它的类别

    lineOut.motion.lblType=DIRECT;//暂时不支持其它的类别

    lineOut.motion.motionOffsetType=(MOTION_OFFSET_TYPE)offsetFlag;//暂时不支持其它的类别
    lineOut.motion.offsetPrIndex=offsetPrIndex.toInt();
    lineOut.motion.motionToolOffsetType=(MOTION_TOOL_OFFSET_TYPE)toolOffsetFlag;//暂时不支持其它的类别

    lineOut.motion.motionWjntType=wjntFlag;

    lineOut.motion.motionIncType=incFlag;

    lineOut.motion.motionPthType=pthFlag;

    lineOut.motion.motionOffsetValue=0;//暂时不支持其它的类别

    lineOut.motion.motionToolOffsetValue=0;//暂时不支持其它的类别

    lineOut.motion.evFlag=evFlag;

    lineOut.motion.evValue=evValue;

    lineOut.motion.motionDiType=diFlag;
    lineOut.motion.diValue=diIndex.toInt();
    lineOut.motion.lblValue=labelIndex;

    return 1;
}



/****************MOTION指令处理函数********＊********/
//int ProgramRegExp::patMotion(QString programStr,QString forwardLineString, Line &lineOut)
//{
//    lineOut.type = MOTION;

//    QRegExp rx_currentLine("^\\s*([A-Z_]*)\\-?\\s*([BEXND]{0,3})\\s*\\_?\\d*\\s*([PAL]{0,3})\\s*(.*)");
//    QRegExp rxForward("\\s*([A-Z_]*)\\s+(.*)");

//    programStr.indexOf(rx_currentLine);
//    forwardLineString.indexOf(rxForward);

//    QRegExp rx(str_rx_MOTION_JLA);
//    QRegExp rx2(str_rx_MOTION_C1);
//    QRegExp rx3(str_rx_MOTION_C2);

//    programStr.indexOf(rx);
//    programStr.indexOf(rx2);
//    programStr.indexOf(rx3);
//    /***********motionformat*****************/
//    if("J" == rx_currentLine.cap(1))
//    {
//        lineOut.motion.motionFormat = J;
//        lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
//    }
//    else if("L" == rx_currentLine.cap(1))
//    {
//        lineOut.motion.motionFormat = L;
//        lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
//    }
//    else if("C" == rxForward.cap(1))
//    {
//        lineOut.motion.motionFormat = C;
//    }
//    else if("A" == rx_currentLine.cap(1))
//    {
//        lineOut.motion.motionFormat = A;
//        lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
//    }
//    else
//    {
//        lineOut.motion.motionFormat = C;
////        return 1;//圆弧有２行，怎么处理？
//    }
////     if("J" == rx.cap(1))
////     {
////         lineOut.motion.motionFormat = J;
////         lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
////     }
////     else if("L" == rx.cap(1))
////     {
////         lineOut.motion.motionFormat = L;
////         lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
////     }
////     else if("A" == rx.cap(1))
////     {
////         lineOut.motion.motionFormat = A;
////         lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
////     }
////     else
////     {
////         lineOut.motion.motionFormat = C;
////     }

//     if(C == lineOut.motion.motionFormat)
//     {
//         if(rx2.cap(1) == "C")
//         {
//             lineOut.motion.circleFlag = CIRCLE_START;
//             QString positionType = strFilt(rx2.cap(2));
//             if(positionType == "P")
//             {
//                 lineOut.motion.positionFormat = P;
//             }
//             else if(positionType == "PR")
//             {
//                 lineOut.motion.positionFormat = PR;
//             }
//             QString positionStr = strFilt(rx2.cap(3));
//             if("R[]" == positionStr)
//             {
//                 lineOut.motion.pointType = INDIRECT;
//             }
//             else
//             {
//                 lineOut.motion.pointType = DIRECT;
//             }
//             short pi = strToInt(rx2.cap(3));
//             lineOut.motion.p = pi;
////             qDebug()<<__FUNCTION__<<"***C***"<<CIRCLE_START<<"**line***"<<__LINE__<<"****P***"<<pi<<endl;

//             QString offsetStr = strFilt(rx2.cap(4));
//             if("Offset" == offsetStr)
//             {
//                   QString rStr = strFilt(rx2.cap(7));
//                   if("R[" == rStr)
//                   {
//                       lineOut.motion.motionOffsetType = MOTION_OFFSET_PR_R;
//                   }
//                   else
//                   {
//                        lineOut.motion.motionOffsetType = MOTION_OFFSET_PR;
//                   }

//                   int prValue = strToInt(rx2.cap(7));
//                   lineOut.motion.motionOffsetValue = prValue;
//             }
//             else
//             {
//                 lineOut.motion.motionOffsetType = MOTION_OFFSET_NONEXIST;
//             }

//             QString toolStr = rx2.cap(10);
//             if("Tool_Offset" == toolStr)
//             {
//                 QString toolRStr = strFilt(rx2.cap(13));
//                 if("R[" == toolRStr)
//                 {
//                     lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_PR_R;
//                 }
//                 else
//                 {
//                     lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_PR;
//                 }

//                 int toolRValue = strToInt(rx2.cap(13));
//                 lineOut.motion.motionToolOffsetValue = toolRValue;
//             }
//             else
//             {
//                 lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_NONEXIST;
//             }

//             lineOut.motion.rate = 0.0;

//         }
//         else
//         {
//             lineOut.motion.circleFlag = (CIRCLE_FLAG)CHANGE_NUM;
//             QString positionType = strFilt(rx3.cap(1));
//             if(positionType == "P")
//             {
//                 lineOut.motion.positionFormat = P;
//             }
//             else if(positionType == "PR")
//             {
//                 lineOut.motion.positionFormat = PR;
//             }

//             QString str2 = strFilt(rx3.cap(2));
//             if("R[]" == str2)
//             {
//                 lineOut.motion.pointType = INDIRECT;
//             }
//             else
//             {
//                 lineOut.motion.pointType = DIRECT;
//             }

//             short pi = strToInt(rx3.cap(2));
//             lineOut.motion.p = pi;
////             qDebug()<<__FUNCTION__<<"***C***"<<CHANGE_NUM<<"**line***"<<__LINE__<<"****P***"<<pi<<endl;

//             double rate= strToDouble(rx3.cap(3));
//             lineOut.motion.rate = rate;
//             QString ratinfo = strFilt(rx3.cap(3));


//             if(ratinfo == "%")
//             {
//                 lineOut.motion.rateFormat = PERCENT;
//             }
//             else if(ratinfo == "mm/sec")
//             {
//                 lineOut.motion.rateFormat = MM_SEC;
//             }
//             else if(ratinfo == "cm/min")
//             {
//                 lineOut.motion.rateFormat = CM_MIN;
//             }
//             else if(ratinfo == "deg/sec")
//             {
//                 lineOut.motion.rateFormat = DEG_SEC;
//             }
//             else if(ratinfo == "sec")
//             {
//                 lineOut.motion.rateFormat = SEC;
//             }
//             else if(ratinfo == "msec")
//             {
//                 lineOut.motion.rateFormat = MSEC;
//             }
//             QString cntformat = strFilt(rx3.cap(4));

//             //qDebug() << __FUNCTION__<<"******"<<__LINE__<<"**rate**"<<rate<<"**ratinfo**"<<ratinfo<<"**cnfFormat**"<<cntformat<<endl;
//             if(cntformat == "FINE")
//             {
//                 lineOut.motion.cntFormat = FINE;
//             }
//             else if(cntformat == "CNT")
//             {
//                 lineOut.motion.cntFormat = CNT;
//                 int cnt = strToInt(rx3.cap(5));
//                 lineOut.motion.cnt = cnt;
//             }

//             QString str6 = rx3.cap(6);
//             if("Wjnt" == str6)
//             {
//                 lineOut.motion.motionWjntType = MOTION_WJNT_EXIST;
//             }
//             else
//             {
//                 lineOut.motion.motionWjntType = MOTION_WJNT_NONEXIST;
//             }
//             QString str7 = rx3.cap(7);
//             if("INC" == str7)
//             {
//                 lineOut.motion.motionIncType = MOTION_INC_EXIST;
//             }
//             else
//             {
//                 lineOut.motion.motionIncType = MOTION_INC_NONEXIST;
//             }
//             QString str8 = rx3.cap(8);
//             if("ACC" == str8)
//             {
//                 short motionAcc = strToInt(rx3.cap(9));
//                 lineOut.motion.acc = motionAcc;
//             }
//             else
//             {
//                  lineOut.motion.acc = 100;
//             }
//             QString str10 = rx3.cap(10);
//             if("EV" == str10)
//             {
//                 int motionEv= strToInt(rx3.cap(11));
//                 lineOut.motion.evValue = motionEv;
//                 lineOut.motion.evFlag = 1;
//             }
//             else
//             {
//                 lineOut.motion.evValue = 0;
//                 lineOut.motion.evFlag = 0;
//             }
//             QString str12 = rx3.cap(12);
//             if("PTH" == str12)
//             {
//                 lineOut.motion.motionPthType = MOTION_PTH_EXIST;
//             }
//             else
//             {
//                   lineOut.motion.motionPthType = MOTION_PTH_NONEXIST;
//             }

//             QString str13 = rx3.cap(13);
//             if("Offset" == str13)
//             {
//                 QString str16 = strFilt(rx3.cap(16));
//                 if("R[" == str16)
//                 {
//                     lineOut.motion.motionOffsetType = MOTION_OFFSET_PR_R;
//                 }
//                 else
//                 {
//                     lineOut.motion.motionOffsetType = MOTION_OFFSET_PR;
//                 }
//                 int offsetVal = strToInt(rx3.cap(16));
//                 lineOut.motion.motionOffsetValue = offsetVal;
//             }
//             else
//             {
//                 lineOut.motion.motionOffsetType = MOTION_OFFSET_NONEXIST;
//             }

//             QString str19 = rx3.cap(19);
//             if("Tool_Offset" == str19)
//             {
//                 QString str22 = strFilt(rx3.cap(22));
//                 if("R[" == str22)
//                 {
//                     lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_PR_R;
//                 }
//                 else
//                 {
//                     lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_PR;
//                 }
//                 int offsetVal = strToInt(rx3.cap(22));
//                 lineOut.motion.motionToolOffsetValue = offsetVal;
//             }
//             else
//             {
//                 lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_NONEXIST;
//             }
//         }
//     }
//     else
//     {
//         QString positionType = strFilt(rx.cap(2));

//         if(positionType == "P")
//         {
//             lineOut.motion.positionFormat = P;
//             QString str3 = strFilt(rx.cap(3));
//             if("R[]" == str3)
//             {
//                 lineOut.motion.pointType = INDIRECT;
//             }
//             else
//             {
//                 lineOut.motion.pointType = DIRECT;
//             }

//             short pi = strToInt(rx.cap(3));
//             lineOut.motion.p = pi;
//         }
//         else if(positionType == "PR")
//         {
//             lineOut.motion.positionFormat = PR;
//             QString str3 = strFilt(rx.cap(3));
//             if("R[]" == str3)
//             {
//                 lineOut.motion.pointType = INDIRECT;
//             }
//             else
//             {
//                 lineOut.motion.pointType = DIRECT;
//             }
//             short pi = strToInt(rx.cap(3));
//             lineOut.motion.p = pi;
//         }
//         else if(positionType == "PAL")
//         {
//             short palNum =  strToInt(rx.cap(2));//PAL编号
//             lineOut.motion.palNum = palNum;

//             QString palPType = strFilt(rx.cap(3));
//             if(palPType == "A")
//             {
//                 lineOut.motion.positionFormat = PAL_A;
//                 short palPNum = strToInt(rx.cap(3));
//                 lineOut.motion.p = palPNum;
//             }
//             else if(palPType == "BTM")
//             {
//                 lineOut.motion.positionFormat = PAL_BTM;
//             }
//             else if(palPType == "R")
//             {
//                 lineOut.motion.positionFormat = PAL_R;
//                 short palPNum = strToInt(rx.cap(3));
//                 lineOut.motion.p = palPNum;
//             }
//         }
//         else
//         {
//             qDebug()<<"error, unknow point type";
//             return -2;
//         }

//         /**********ratformat********************/
//         double rate= strCharsToDouble(rx.cap(4));
//         lineOut.motion.rate = rate;
//         QString ratinfo = strFilt(rx.cap(4));
//         if(ratinfo == "%")
//         {
//             lineOut.motion.rateFormat = PERCENT;
//         }
//         else if(ratinfo == "mm/sec")
//         {
//             lineOut.motion.rateFormat = MM_SEC;
//         }
//         else if(ratinfo == "cm/min")
//         {
//             lineOut.motion.rateFormat = CM_MIN;
//         }
//         else if(ratinfo == "deg/sec")
//         {
//             lineOut.motion.rateFormat = DEG_SEC;
//         }
//         else if(ratinfo == "sec")
//         {
//             lineOut.motion.rateFormat = SEC;
//         }
//         else if(ratinfo == "msec")
//         {
//             lineOut.motion.rateFormat = MSEC;
//         }

//         /**************cntFormat***************/
//         QString cntformat = strFilt(rx.cap(5));
//         if(cntformat == "FINE")
//         {
//             lineOut.motion.cntFormat = FINE;
//         }
//         else if(cntformat == "CNT")
//         {
//             lineOut.motion.cntFormat = CNT;
//             int cnt = strToInt(rx.cap(6));
//             lineOut.motion.cnt = cnt;
//         }

//         /**************ADDTIONAL*******************/
//         QString str7 = rx.cap(7);
//         if("Wjnt" == str7)
//         {
//             lineOut.motion.motionWjntType = MOTION_WJNT_EXIST;
//         }
//         else
//         {
//             lineOut.motion.motionWjntType = MOTION_WJNT_NONEXIST;
//         }
//         QString str8 = rx.cap(8);
//         if("INC" == str8)
//         {
//             lineOut.motion.motionIncType = MOTION_INC_EXIST;
//         }
//         else
//         {
//             lineOut.motion.motionIncType = MOTION_INC_NONEXIST;
//         }
//         QString str9 = rx.cap(9);
//         if("ACC" == str9)
//         {
//             short motionAcc = strToInt(rx.cap(10));
//             lineOut.motion.acc = motionAcc;
//         }
//         else
//         {
//              lineOut.motion.acc = 100;
//         }
//         QString str11 = rx.cap(11);
//         if("EV" == str11)
//         {
//             int motionEv= strToInt(rx.cap(12));
//             lineOut.motion.evValue = motionEv;
//             lineOut.motion.evFlag = 1;
//         }
//         else
//         {
//             lineOut.motion.evValue = 0;
//             lineOut.motion.evFlag = 0;
//         }
//         QString str13 = rx.cap(13);
//         if("PTH" == str13)
//         {
//             lineOut.motion.motionPthType = MOTION_PTH_EXIST;
//         }
//         else
//         {
//               lineOut.motion.motionPthType = MOTION_PTH_NONEXIST;
//         }

//         QString str14 = rx.cap(14);
//         if("Offset" == str14)
//         {
//             QString str17 = strFilt(rx.cap(17));
//             if("R[" == str17)
//             {
//                 lineOut.motion.motionOffsetType = MOTION_OFFSET_PR_R;
//             }
//             else
//             {
//                 lineOut.motion.motionOffsetType = MOTION_OFFSET_PR;
//             }
//             int offsetVal = strToInt(rx.cap(17));
//             lineOut.motion.motionOffsetValue = offsetVal;
//         }
//         else
//         {
//             lineOut.motion.motionOffsetType = MOTION_OFFSET_NONEXIST;
//         }

//         QString str20 = rx.cap(20);
//         if("Tool_Offset" == str20)
//         {
//             QString str23 = strFilt(rx.cap(23));
//             if("R[" == str23)
//             {
//                 lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_PR_R;
//             }
//             else
//             {
//                 lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_PR;
//             }
//             int offsetVal = strToInt(rx.cap(23));
//             lineOut.motion.motionToolOffsetValue = offsetVal;
//         }
//         else
//         {
//             lineOut.motion.motionToolOffsetType = MOTION_TOOL_OFFSET_NONEXIST;
//         }
//     }
//     return 1;

//}


int ProgramRegExp::patPause(QString programStr, Line &lineOut)
{
    lineOut.type = PAUSE;
    return 1;
}

int ProgramRegExp::patAbort(QString programStr, Line &lineOut)
{
    lineOut.type = ABORT;
    return 1;
}

int ProgramRegExp::patEnd(QString programStr, Line &lineOut)
{
    lineOut.type = END;
    return 1;
}

int ProgramRegExp::patUalm(QString programStr, Line &lineOut)
{
    lineOut.type = UALM;

    QRegExp rx(str_rx_ualm);

    int index = programStr.indexOf(rx);

    if("UALM" == rx.cap(1))
    {
        lineOut.ualmInstruct.ualmStr = rx.cap(3);
    }

    return 1;
}

int ProgramRegExp::patMessage(QString programStr, Line &lineOut)
{
    lineOut.type = MESSAGE;

    QRegExp rx(str_rx_message);

    int index = programStr.indexOf(rx);

    if("MESSAGE" == rx.cap(1))
    {
        lineOut.messageInstruct.messageStr = rx.cap(3);
    }

    return 1;
}

int ProgramRegExp::patOverride(QString programStr, Line &lineOut)
{
    lineOut.type = OVERRIDE;

    QRegExp rx(str_rx_override);

   int index = programStr.indexOf(rx);

   if("OVERRIDE" ==  rx.cap(1))
   {
       QString str2 = strFilt(rx.cap(2));
       if("AR[]" == str2)
       {
           lineOut.overrideInstruct.overrideType = OVERRIDE_VALUE_AR;
       }
       else if("R[]" == str2)
       {
            lineOut.overrideInstruct.overrideType = OVERRIDE_VALUE_R;
       }
       else
       {
            lineOut.overrideInstruct.overrideType = OVERRIDE_VALUE_CONST;
       }

       int overValue = strToInt(rx.cap(2));

       lineOut.overrideInstruct.overrideValue = overValue;
   }

   return 1;

}

int ProgramRegExp::patTimer(QString programStr, Line &lineOut)
{
    lineOut.type = TIMER;

    int ownerStart = programStr.indexOf("//");
    programStr = programStr.left(ownerStart);

    QRegExp rx(str_rx_timer_cmd + srt_rx_notes);
    QRegExp rx2(str_rx_timer_value);

    programStr.indexOf(rx);
    programStr.indexOf(rx2);

    if("TIMER" == rx.cap(1))
    {
        int timerFront = strToInt(rx.cap(2));
        QString str3 = strFilt(rx.cap(3));
        if("START" == str3)
        {
            lineOut.timerInstruct.timerProcessType = TIMER_PROCESS_START;
        }
        else if("STOP" == str3)
        {
            lineOut.timerInstruct.timerProcessType = TIMER_PROCESS_STOP;
        }
        else if("RESET" == str3)
        {
            lineOut.timerInstruct.timerProcessType = TIMER_PROCESS_RESET;
        }
        lineOut.timerInstruct.front_value = timerFront;
    }
    else
    {
        lineOut.timerInstruct.timerProcessType = TIMER_PROCESS_REG;
        int timerFront = strToInt(rx2.cap(2));
        lineOut.timerInstruct.front_value = timerFront;
        /*************存储等号右边的内容，放入QMap中***************/
        QMap<int,QString> map;
        QString strpro = rx2.cap(3);
        strpro.replace(QString(" "),QString(""));
        strpro.replace(";","");

        QString strchar;
        QStringList strList;
        int xi = 0;
        int p1;
        int p2;

//        qDebug() << "===strpro==="<< strpro<<endl;

        strchar = "R[:PR";
        strList = strchar.split(":");
        /*********R[i]***********/
        p1 = strpro.indexOf(strchar);

        while(xi < strList.length())
        {
            p1 = strpro.indexOf(strList[xi]);
            if(p1 != -1)
            {
                p2 = p1;
                while(1)
                {
                    if(strpro.mid(p2,1) == "]")
                        break;
                    p2++;
                }
                QString strget = strpro.mid(p1,p2-p1+1);
//                qDebug() << "==strget==="<<strget<<endl;
                map.insert(p1,strget);      //插入到QMAP中

                strpro.replace(p1,2,"@@");
                strget.replace(0,2,"@@");   //因为PR[R[]]里面有两个R；
                int R = strget.indexOf("R");     //判断字符串里面是否有R[]，如果有应该替换掉，避免误认为是外面的R[];
                if(R != -1)
                {
                    strpro.replace(p1+R,1,"@");
                }
            }
            else if(-1 == p1)
            {
                xi++;
            }
        }
        qDebug() << "****strpro*****"<<strpro<<endl;

        /***************获取“+-* / ( )******************/
        strchar = "+ - * / ( )";
        strList = strchar.split(" ");
        xi  = 0;
        int op = 0;
        while(xi < strList.length() )
        {
            op = strpro.indexOf(strList[xi]);
            if(op != -1)
            {
                QString oper = strpro.mid(op,1);
                map.insert( op,oper);     //插入到QMAP
                strpro.replace(op,1,"#");
            }
            else if(op == -1)
            {
                xi++;
            }
        }
//       qDebug() << "****strpro**+++++++***"<<strpro<<endl;

       /**************获取常数项***************/
       while(1)
       {
           p1 = strpro.indexOf("#");
           if(p1 == -1)
           {
               break;
           }
           if(strpro.mid(p1+1,1)>="0" && strpro.mid(p1+1,1)<="9")
           {
               p2 = p1;
               while(1)
               {
                   p2++;
                   if(strpro.mid(p2,1) == "#" || strpro.mid(p2,1) == "")
                   {
                       break;
                   }
               }
               QString strget = strpro.mid(p1+1,p2-p1-1);
               map.insert(p1+1,strget);      //插入到QMAP中
           }
           strpro.replace(p1,1,"$");
       }
//       qDebug() << "****strpro**$$$$$$***"<<strpro<<endl;

       if(strpro.mid(0,1) >= "0" && strpro.mid(0,1)<="9")
       {
           p1 = 0;
           while(1)
           {
               p1++;
               qDebug()<< "---mid---"<<strpro.mid(p1,1)<<endl;
               if(strpro.mid(p1,1) == "$")
               {
                   break;
               }
               else if(strpro.mid(p1,1) == "")
               {
                   break;
               }
           }
           QString strget = strpro.mid(0,p1);
           map.insert(0,strget);      //插入到QMAP中
       }

//        qDebug() << "****last***"<<strpro<<endl;
       /****************将获得的每个字符串顺序存储***************/
         int sum = 0;
         float val;
         QMap<int, QString>::const_iterator mi;
         for( mi=map.constBegin(); mi!=map.constEnd(); ++mi)
         {
//             qDebug() <<"====map==="<<mi.value()<<endl;
             sum++;
             lineOut.reg.regcondition.resize(sum);

             strList = mi.value().split("[");

             if("R" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_R;
             }
             else if("+" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_ADD;
             }
             else if("-" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_DEC;
             }
             else if("*" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_MUL;
             }
             else if("/" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_DIVIVIDE;
             }
             else if("(" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_LEFT_BRK;
             }
             else if(")" == strList[0])
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_RIGHT_BRK;
             }
             else
             {
                 lineOut.reg.regcondition[sum -1].valueType = REG_CONST;
                 val = (float)strToDouble(strList[0]);
                 lineOut.reg.regcondition[sum -1].val = val;
             }

             /***************判断地址类型*****************/
             if(strList.size() > 1)
             {
                 if("R" == strList[1])
                 {
                     lineOut.reg.regcondition[sum -1].rightVarType = INDIRECT;
                 }
                 else
                 {
                     lineOut.reg.regcondition[sum -1].rightVarType = DIRECT;
                 }
             }
         }
    }

    return 1;
}

int ProgramRegExp::patRsr(QString programStr, Line &lineOut)
{
    lineOut.type = RSR;

    QRegExp rx(str_rx_rsr);
    programStr.indexOf(rx);

    QString str1 = strFilt(rx.cap(1));

    if("RSR[]" == str1)
    {
        int rsrNumber = strToInt(rx.cap(1));

        QString str2 = strFilt(rx.cap(2));
        if("ENABLE" == str2)
        {
            lineOut.rsrInstruct.rsrType = RSR_ENABLE;
        }
        else if("DISABLE" == str2)
        {
            lineOut.rsrInstruct.rsrType = RSR_DISABLE;
        }
        else
        {
            lineOut.rsrInstruct.rsrType = RSR_DISABLE;
        }

        lineOut.rsrInstruct.rsrNum = rsrNumber;
    }

    return 1;
}

int ProgramRegExp::patAnnotation(QString programStr, Line &lineOut)
{
    lineOut.type = ANOTATION;
    return 1;
}

/*******************************************
 * 日期：2018年6月1日
 * 修改人：hualei
 * 修改内容:添加 MODBUS_START、MODBUS_READ、MODBUS_WRITE 指令
 * *****************************************/

/******************** MODBUS_START指令 ********************/
int ProgramRegExp::patModbusStart(QString programStr, Line &lineOut)
{
    lineOut.type = MODBUS_START;

    // 创建一个正则表达式对象
    QRegExp rxModbusStart(str_rx_modbusStart);

    // 查找程序字符串中是否有符合表达式的字符串
    programStr.indexOf(rxModbusStart);

    bool match;
    // 查找程序字符串中是否有符合表达式的字符串
    // exactMatch函数，如果programStr完全与此正则表达式匹配，则返回true ; 否则返回false
    // 提取modbus类型为 INTERNET 时的指令参数
    if((match = rxModbusStart.exactMatch(programStr)) == true)
    {
        // 提取指令名
        QString str1 = strFilt(rxModbusStart.cap(1));
        if("MODBUSSTART"==str1)
        {
            lineOut.modbusStartInstruction.instructionType = MODBUS_START;
        }

        // 提取busId
        int busId = strToInt(rxModbusStart.cap(3));
        lineOut.modbusStartInstruction.busId = busId;

        // 提取modbus类型
        QString str2 = strFilt(rxModbusStart.cap(5));
        if(str2 == "INTERNETMASTER")
        {
            // 提取modbus类型
            lineOut.modbusStartInstruction.modbusType = E_MODBUS_SPEC_TYPE_INTERNET_MASTER;
        }
        else if(str2 == "INTERNETSLAVE")
        {
            lineOut.modbusStartInstruction.modbusType = E_MODBUS_SPEC_TYPE_INTERNET_SLAVE;
        }
        else if(str2 == "RSMASTER")
        {
            lineOut.modbusStartInstruction.modbusType = E_MODBUS_SPEC_TYPE_RS485_MASTER;
        }
        else if(str2 == "RSSLAVE")
        {
            lineOut.modbusStartInstruction.modbusType = E_MODBUS_SPEC_TYPE_RS485_SLAVE;
        }
        else
        {
            lineOut.modbusStartInstruction.modbusType = E_MODBUS_SPEC_TYPE_ERROR;
        }
        // 提取jmpLable
        QString jmp = strFilt(rxModbusStart.cap(8));
        QString lb = strFilt(rxModbusStart.cap(9));
        int labelNum = strToInt(rxModbusStart.cap(9));
        lineOut.modbusStartInstruction.jmpLable = QString("%1").arg(labelNum);
        lineOut.modbusStartInstruction.noteStr = strFilt(rxModbusStart.cap(11));

//        qDebug() << "ProgramRegExp::patModbusStart ==== instructionType:"<< lineOut.modbusStartInstruction.instructionType;
//        qDebug() << "ProgramRegExp::patModbusStart ==== BusId:"<< lineOut.modbusStartInstruction.busId;
//        qDebug() << "ProgramRegExp::patModbusStart ==== ModbusType:"<< lineOut.modbusStartInstruction.modbusType ;
//        qDebug() << "ProgramRegExp::patModbusStart ==== LabelNum:"<< lineOut.modbusStartInstruction.jmpLable;
//        qDebug() << "=======================================================";
    }

    return 1;
}

/******************** MODBUS_READ指令 ********************/
int ProgramRegExp::patModbusRead(QString programStr, Line &lineOut)
{
    // 加入指令类型
    lineOut.type = MODBUS_READ;

    // 构造正则表达式对象
    QRegExp rxModbusRead(str_rx_modbusRead);

    programStr.indexOf(rxModbusRead);

    bool matchResult;

    if((matchResult = rxModbusRead.exactMatch(programStr)) == true)
    {

        lineOut.modbusReadInstruction.instructionType = MODBUS_READ;


        lineOut.modbusReadInstruction.modbusReadDataRegisterIndex = rxModbusRead.cap(3).toInt();
        lineOut.modbusReadInstruction.modbuReadRegAddress = rxModbusRead.cap(4).toInt();
        lineOut.modbusReadInstruction.busId  = rxModbusRead.cap(5);

        if((rxModbusRead.cap(6) == "INTERNET") && (rxModbusRead.cap(7) == "MASTER"))
        {
            lineOut.modbusReadInstruction.modbusType = E_MODBUS_SPEC_TYPE_INTERNET_MASTER;
        }
        else if((rxModbusRead.cap(6) == "INTERNET") && (rxModbusRead.cap(7) == "SLAVE"))
        {
            lineOut.modbusReadInstruction.modbusType = E_MODBUS_SPEC_TYPE_INTERNET_SLAVE;
        }
        else if((rxModbusRead.cap(6) == "RS485") && (rxModbusRead.cap(7) == "SLAVE"))
        {
            lineOut.modbusReadInstruction.modbusType = E_MODBUS_SPEC_TYPE_RS485_SLAVE;
        }
        else if((rxModbusRead.cap(6) == "RS485") && (rxModbusRead.cap(7) == "MASTER"))
        {
            lineOut.modbusReadInstruction.modbusType = E_MODBUS_SPEC_TYPE_RS485_MASTER;
        }

        if(rxModbusRead.cap(8) == "JMP")
        {
            lineOut.modbusReadInstruction.jmpLable = rxModbusRead.cap(10);
//            qDebug()<<rxModbusRead.cap(10);
        }

        lineOut.modbusReadInstruction.noteStr = rxModbusRead.cap(12);
        return 1;
    }

    return -1;

}

/******************** MODBUS_WRITE指令 ********************/
int ProgramRegExp::patModbusWrite(QString programStr, Line &lineOut)
{
    // 加入指令类型
    lineOut.type = MODBUS_WRITE;
    // 构造正则表达式对象
    QRegExp rxModbusWrite(str_rx_modbusWrite);

    bool matchResult = rxModbusWrite.exactMatch(programStr);
    if(matchResult)
    {
        lineOut.modbusWriteInstruction.instructionType = MODBUS_WRITE;
        QString readR = rxModbusWrite.cap(2);
        if(readR.startsWith("R"))
        {
            lineOut.modbusWriteInstruction.writeSourceType = REG_CONST;
            // 提取写入寄存器数值
            lineOut.modbusWriteInstruction.robotRegisterIndex = rxModbusWrite.cap(5).toInt();
            lineOut.modbusWriteInstruction.constWriteData = 0x00;
        }
        else
        {
            lineOut.modbusWriteInstruction.writeSourceType = CONST_DATA;
            lineOut.modbusWriteInstruction.constWriteData = rxModbusWrite.cap(2).toInt();
            lineOut.modbusWriteInstruction.robotRegisterIndex = 0;
        }

        lineOut.modbusWriteInstruction.modbuWriteRegAddress =rxModbusWrite.cap(6).toInt();
        lineOut.modbusWriteInstruction.busId = rxModbusWrite.cap(7);


        if((rxModbusWrite.cap(8) == "INTERNET") && (rxModbusWrite.cap(9) == "MASTER"))
        {
            lineOut.modbusWriteInstruction.modbusType = E_MODBUS_SPEC_TYPE_INTERNET_MASTER;
        }
        else if((rxModbusWrite.cap(8) == "INTERNET") && (rxModbusWrite.cap(9) == "SLAVE"))
        {
            lineOut.modbusWriteInstruction.modbusType = E_MODBUS_SPEC_TYPE_INTERNET_SLAVE;
        }
        else if((rxModbusWrite.cap(8) == "RS485") && (rxModbusWrite.cap(9) == "MASTER"))
        {
            lineOut.modbusWriteInstruction.modbusType = E_MODBUS_SPEC_TYPE_RS485_MASTER;
        }
        else if((rxModbusWrite.cap(8) == "RS485") && (rxModbusWrite.cap(9) == "SLAVE"))
        {
           lineOut.modbusWriteInstruction.modbusType = E_MODBUS_SPEC_TYPE_RS485_SLAVE;
        }
        else
        {
            lineOut.modbusWriteInstruction.modbusType = E_MODBUS_SPEC_TYPE_ERROR;
        }

        lineOut.modbusWriteInstruction.jmpLable = rxModbusWrite.cap(12);
        lineOut.modbusWriteInstruction.noteStr = rxModbusWrite.cap(14);
        return 1;
    }
    return -1;
}

int ProgramRegExp::patMoveMag(QString programStr,Line &lineOut)
{
    lineOut.type = MOVE_MAG;

    QRegExp rxMoveMag(str_rx_moveMag);

    programStr.indexOf(rxMoveMag);
    bool matchResult;

    if((matchResult = rxMoveMag.exactMatch(programStr)) == true)
    {
        lineOut.moveMagInstruction.instructionType = MOVE_MAG;

        QString str1 = strFilt(rxMoveMag.cap(2));
        QString str2 = strFilt(rxMoveMag.cap(3));

        if(str1 == "L")
        {
            lineOut.moveMagInstruction.moveMagDirectionLMR = E_MOVE_MAG_LEFT_DIRECTION;
        }
        else if(str1 == "M")
        {
            lineOut.moveMagInstruction.moveMagDirectionLMR = E_MOVE_MAG_MIDDLE_DIRECTION;
        }
        else if(str1 == "R")
        {
            lineOut.moveMagInstruction.moveMagDirectionLMR = E_MOVE_MAG_RIGHT_DIRECTION;
        }

        if(str2 == "BACK")
        {
            lineOut.moveMagInstruction.moveMagDirectionFB = E_MOVE_MAG_BACK_DIRECTION;
        }
        else if(str2 == "FRONT")
        {
            lineOut.moveMagInstruction.moveMagDirectionFB = E_MOVE_MAG_FRONT_DIRECTION;
        }

        lineOut.moveMagInstruction.velocityRatio = strToInt(rxMoveMag.cap(4));

        if((str1 = strFilt(rxMoveMag.cap(7))) == "RFID")
        {
            int rfidValue = strToInt(rxMoveMag.cap(8));
            lineOut.moveMagInstruction.rfidInternalValue = QString("%1").arg(rfidValue);
        }

        if(rxMoveMag.cap(10) == "RFID_STOP")
        {
            lineOut.moveMagInstruction.stopType = E_MOVE_MAG_RFID_STOP;
            lineOut.moveMagInstruction.stopInputNum = 0;
        }
        else if(rxMoveMag.cap(11) == "MAG_STOP")
        {
            lineOut.moveMagInstruction.stopType = E_MOVE_MAG_MAG_WIDTH_STOP;
            lineOut.moveMagInstruction.stopInputNum = 0;
        }
        else if(rxMoveMag.cap(12).contains("INPUT"))
        {
            lineOut.moveMagInstruction.stopType = E_MOVE_MAG_INPUT_STOP;
            lineOut.moveMagInstruction.stopInputNum = strToInt(rxMoveMag.cap(13));
        }
        else if(rxMoveMag.cap(9) == " ")
        {
            lineOut.moveMagInstruction.stopType = E_MOVE_MAG_NO_STOP;
            lineOut.moveMagInstruction.stopInputNum = 0;
        }
        lineOut.moveMagInstruction.noteStr = strFilt(rxMoveMag.cap(15));

    }
    else
    {
        return -1;
    }
    return 1;

}

/*****************************  MOVE_FREE  *******************************/
int ProgramRegExp::patMoveFree(QString programStr,Line &lineOut)
{
    lineOut.type = MOVE_FREE;

    QRegExp rxMoveFree(str_rx_moveFree);

    programStr.indexOf(rxMoveFree);
    bool matchResult;
    if((matchResult = rxMoveFree.exactMatch(programStr)) == true)
    {

        lineOut.moveFreeInstruction.instructionType = MOVE_FREE;

        QString str1 = strFilt(rxMoveFree.cap(2));
        QString str2 = strFilt(rxMoveFree.cap(5));
        QString str3 = strFilt(rxMoveFree.cap(6));
        QString str4 = strFilt(rxMoveFree.cap(9));

        if(str1 == "DP")
        {
            lineOut.moveFreeInstruction.pointArryType = E_MOVE_FREE_POINTS_ARRY_DP;
            lineOut.moveFreeInstruction.pointsValue = rxMoveFree.cap(3).toInt();
            lineOut.moveFreeInstruction.registerPointsValue = 0;
            lineOut.moveFreeInstruction.trackMoveFileName = "";
        }
        else if(str1 == "DPR")
        {
            lineOut.moveFreeInstruction.pointArryType = E_MOVE_FREE_POINTS_ARRY_DPR;
            lineOut.moveFreeInstruction.pointsValue = 0;
            lineOut.moveFreeInstruction.registerPointsValue = rxMoveFree.cap(3).toInt();
            lineOut.moveFreeInstruction.trackMoveFileName = "";
        }
        else if(str1 == "DPL")
        {
            lineOut.moveFreeInstruction.pointArryType = E_MOVE_FREE_POINTS_ARRY_DPL;
            lineOut.moveFreeInstruction.pointsValue = 0;
            lineOut.moveFreeInstruction.registerPointsValue = 0;
            lineOut.moveFreeInstruction.trackMoveFileName = rxMoveFree.cap(3);
        }

        if(str2 == "WHEEL")
        {
            lineOut.moveFreeInstruction.moveFreeMode = E_MOVE_FREE_WHEEL;
        }
        else if(str2 == "IMU")
        {
            lineOut.moveFreeInstruction.moveFreeMode = E_MOVE_FREE_IMU;
        }
        else if(str2 == "LASER")
        {
            lineOut.moveFreeInstruction.moveFreeMode = E_MOVE_FREE_LASER;
        }

        lineOut.moveFreeInstruction.velocityRatio = rxMoveFree.cap(4).toInt();

        if(str3 == "FINE")
        {
            lineOut.moveFreeInstruction.CNT_Value = 0;
        }
        else
        {
            lineOut.moveFreeInstruction.CNT_Value = strToInt(rxMoveFree.cap(6));;
        }

        if(str4 == "AUTO")
        {
            lineOut.moveFreeInstruction.moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_AUTO;
        }
        else if(str4 == "LINE")
        {
            lineOut.moveFreeInstruction.moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_LINE;
        }
        else if(str4 == "SPLINE")
        {
            lineOut.moveFreeInstruction.moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_SPLINE;
        }
        else if(str4 == "ROTATE")
        {
            lineOut.moveFreeInstruction.moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_ROTATE;
        }

        str1 = rxMoveFree.cap(10);
        if(str1 == "P")
        {
            lineOut.moveFreeInstruction.isPositiveDirection = true;
        }
        else if(str1 == "N")
        {
            lineOut.moveFreeInstruction.isPositiveDirection = false;
        }

        lineOut.moveFreeInstruction.allowAccuracy = rxMoveFree.cap(11).toDouble();

        // VMark 点位类型
        if(rxMoveFree.cap(14).contains("VMark["))
        {
            lineOut.moveFreeInstruction.pointIndex = rxMoveFree.cap(16).toInt();
            lineOut.moveFreeInstruction.pointSensorType = EM_MOVE_FREE_VMARK;
        }
        // QR 二维码点位类型
        else if(rxMoveFree.cap(14).contains("QR["))
        {
            lineOut.moveFreeInstruction.pointIndex = rxMoveFree.cap(15).toInt();
            lineOut.moveFreeInstruction.pointSensorType = EM_MOVE_FREE_QR;
        }
        // Ordinary-Point 普通点位类型
        else if(rxMoveFree.cap(14).contains("OP"))
        {
            lineOut.moveFreeInstruction.pointIndex = 0;
            lineOut.moveFreeInstruction.pointSensorType = EM_MOVE_FREE_DP;
        }
        // CU1点位类型
        else if(rxMoveFree.cap(14).contains("CU1"))
        {
            lineOut.moveFreeInstruction.pointIndex = 0;
            lineOut.moveFreeInstruction.pointSensorType = EM_MOVE_FREE_CU1;
        }

        if(rxMoveFree.cap(17).contains("Laser["))
        {
            lineOut.moveFreeInstruction.laserTypeNum = rxMoveFree.cap(18).toInt();
        }

        /*******************************************
         * 日期：2018年10月26日
         * 修改人：丁培
         * 修改内容:添加探测障碍相关属性匹配
         * *****************************************/
        QString tmpDetectStr=rxMoveFree.cap(19);
        if(tmpDetectStr.compare("DET") == 0)
        {
            lineOut.moveFreeInstruction.isDetectBarrier=true;
            lineOut.moveFreeInstruction.barrierRunMode=0;
        }
        else if(tmpDetectStr.compare("NODET") == 0)
        {
            lineOut.moveFreeInstruction.isDetectBarrier=false;
        }
        else
        {
            lineOut.moveFreeInstruction.isDetectBarrier=true;
            lineOut.moveFreeInstruction.barrierRunMode=strToInt(tmpDetectStr);
        }

        lineOut.moveFreeInstruction.jmpLabel = rxMoveFree.cap(24);
        lineOut.moveFreeInstruction.noteStr = rxMoveFree.cap(25);

        //跟线策略
        if(programStr.contains("OMNI"))
        {
            lineOut.moveFreeInstruction.pathControlStrategy=E_PATH_CONTROL_STRATEGY_MCCRUM;
        }
        else
        {
            lineOut.moveFreeInstruction.pathControlStrategy=E_PATH_CONTROL_STRATEGY_DIFFERENTIAL;
        }
    }
    else
    {
        return -1;
    }
    return 1;
}

/***************************  TCP_START  **********************************/
int ProgramRegExp::patTcpStart(QString programStr, Line &lineOut)
{
    lineOut.type = TCP_START;

    QRegExp rxTcpStart(str_rx_tcpStart);

    bool matchResult;
    if((matchResult = rxTcpStart.exactMatch(programStr)) == true)
    {

        lineOut.tcpStartInstruction.instructionType = TCP_START;
        lineOut.tcpStartInstruction.tcpStartPort = rxTcpStart.cap(8).toInt();

        if(rxTcpStart.cap(10) == "SERVER")
        {
            lineOut.tcpStartInstruction.tcpStartBusType = E_TCP_BUSTYPE_SERVER;

            lineOut.tcpStartInstruction.tcpStartClientIPVec[0] = rxTcpStart.cap(3).toInt();
            lineOut.tcpStartInstruction.tcpStartClientIPVec[1] = rxTcpStart.cap(4).toInt();
            lineOut.tcpStartInstruction.tcpStartClientIPVec[2] = rxTcpStart.cap(5).toInt();
            lineOut.tcpStartInstruction.tcpStartClientIPVec[3] = rxTcpStart.cap(6).toInt();
        }
        else if(rxTcpStart.cap(10) == "CLIENT")
        {
            lineOut.tcpStartInstruction.tcpStartBusType = E_TCP_BUSTYPE_CLIENT;

            lineOut.tcpStartInstruction.tcpStartServerIPVec[0] = rxTcpStart.cap(3).toInt();
            lineOut.tcpStartInstruction.tcpStartServerIPVec[1] = rxTcpStart.cap(4).toInt();
            lineOut.tcpStartInstruction.tcpStartServerIPVec[2] = rxTcpStart.cap(5).toInt();
            lineOut.tcpStartInstruction.tcpStartServerIPVec[3] = rxTcpStart.cap(6).toInt();

        }

        lineOut.tcpStartInstruction.jmpLabelValue = rxTcpStart.cap(14).toInt();
        lineOut.tcpStartInstruction.noteStr = rxTcpStart.cap(16);
    }
    else
    {
        return -1;
    }
    return 1;
}


/******************************  TCP_READ  ******************************/
int ProgramRegExp::patTcpRead(QString programStr, Line &lineOut)
{
    lineOut.type = TCP_READ;

    QRegExp rxTcpRead(str_rx_tcpRead);

    bool matchResult;
    if((matchResult = rxTcpRead.exactMatch(programStr)) == true)
    {
        lineOut.tcpReadInstruction.instructionType = TCP_READ;

        lineOut.tcpReadInstruction.tcpReadRegBeginAddress = rxTcpRead.cap(3).toInt();
        lineOut.tcpReadInstruction.tcpReadRegLength = rxTcpRead.cap(5).toInt();

        if(rxTcpRead.cap(12) == "SERVER")
        {
            lineOut.tcpReadInstruction.tcpReadBusType = E_TCP_READ_BUS_SERVER;
            lineOut.tcpReadInstruction.tcpReadClientIPVec[0] = rxTcpRead.cap(7).toInt();
            lineOut.tcpReadInstruction.tcpReadClientIPVec[1] = rxTcpRead.cap(8).toInt();
            lineOut.tcpReadInstruction.tcpReadClientIPVec[2] = rxTcpRead.cap(9).toInt();
            lineOut.tcpReadInstruction.tcpReadClientIPVec[3] = rxTcpRead.cap(10).toInt();
        }
        else if(rxTcpRead.cap(12) == "CLIENT")
        {
            lineOut.tcpReadInstruction.tcpReadBusType = E_TCP_READ_BUS_CLIENT;
            lineOut.tcpReadInstruction.tcpReadServerIPVec[0] = rxTcpRead.cap(7).toInt();
            lineOut.tcpReadInstruction.tcpReadServerIPVec[1] = rxTcpRead.cap(8).toInt();
            lineOut.tcpReadInstruction.tcpReadServerIPVec[2] = rxTcpRead.cap(9).toInt();
            lineOut.tcpReadInstruction.tcpReadServerIPVec[3] = rxTcpRead.cap(10).toInt();
        }

        lineOut.tcpReadInstruction.tcpReadPort = rxTcpRead.cap(11).toInt();
        lineOut.tcpReadInstruction.jmpLBValue = rxTcpRead.cap(15).toInt();
        lineOut.tcpReadInstruction.noteStr = rxTcpRead.cap(17);
    }
    else
    {
        return -1;
    }

    return 1;

}

/**************************  TCP_WRITE  ***********************************/
int ProgramRegExp::patTcpWrite(QString programStr, Line &lineOut)
{
    lineOut.type = TCP_WRITE;

    QRegExp rxTcpWrite(str_rx_tcpWrite);

    bool matchResult;
    if((matchResult = rxTcpWrite.exactMatch(programStr)) == true)
    {
        lineOut.tcpWriteInstruction.instructionType = TCP_WRITE;

        if(rxTcpWrite.cap(2).contains("R"))
        {
            lineOut.tcpWriteInstruction.tcpWriteType = E_TCP_WRITE_TYPE_REGISTER;
            lineOut.tcpWriteInstruction.tcpWriteRegBegAddress = rxTcpWrite.cap(4).toInt();
            lineOut.tcpWriteInstruction.regLengthValue = rxTcpWrite.cap(8).toInt();
            lineOut.tcpWriteInstruction.tcpWriteConstValue = "0";
        }
        else
        {
            lineOut.tcpWriteInstruction.tcpWriteType = E_TCP_WRITE_TYPE_CONST;
            lineOut.tcpWriteInstruction.tcpWriteConstValue = rxTcpWrite.cap(2);
            lineOut.tcpWriteInstruction.tcpWriteRegBegAddress = 1;
            lineOut.tcpWriteInstruction.regLengthValue = 1;
        }

        if(rxTcpWrite.cap(16) == "SERVER")
        {
            lineOut.tcpWriteInstruction.tcpWriteClientIPVec[0] = rxTcpWrite.cap(11).toInt();
            lineOut.tcpWriteInstruction.tcpWriteClientIPVec[1] = rxTcpWrite.cap(12).toInt();
            lineOut.tcpWriteInstruction.tcpWriteClientIPVec[2] = rxTcpWrite.cap(13).toInt();
            lineOut.tcpWriteInstruction.tcpWriteClientIPVec[3] = rxTcpWrite.cap(14).toInt();
            lineOut.tcpWriteInstruction.tcpWriteBusType = E_TCP_WRITE_BUS_SERVER;
        }
        else if(rxTcpWrite.cap(16) == "CLIENT")
        {
            lineOut.tcpWriteInstruction.tcpWriteServerIPVec[0] = rxTcpWrite.cap(11).toInt();
            lineOut.tcpWriteInstruction.tcpWriteServerIPVec[1] = rxTcpWrite.cap(12).toInt();
            lineOut.tcpWriteInstruction.tcpWriteServerIPVec[2] = rxTcpWrite.cap(13).toInt();
            lineOut.tcpWriteInstruction.tcpWriteServerIPVec[3] = rxTcpWrite.cap(14).toInt();
            lineOut.tcpWriteInstruction.tcpWriteBusType = E_TCP_WRITE_BUS_CLIENT;
        }

        lineOut.tcpWriteInstruction.tcpWritePort = rxTcpWrite.cap(15).toInt();
        lineOut.tcpWriteInstruction.jmpLBValue = rxTcpWrite.cap(19).toInt();
        lineOut.tcpWriteInstruction.noteStr = rxTcpWrite.cap(21);
    }
    else
    {
        return -1;
    }

    return 1;

}

/****************************  MUSIC  *****************************/
int ProgramRegExp::patMusic(QString programStr, Line &lineOut)
{
    lineOut.type = MUSIC;

    QRegExp rxMusic(str_rx_music);

    bool matchResult;

    if((matchResult = rxMusic.exactMatch(programStr)) == true)
    {
        lineOut.musicInstruction.instructionType = MUSIC;
        lineOut.musicInstruction.musicFileName = rxMusic.cap(2);
        if(rxMusic.cap(3) == QObject::tr("循环"))
        {
            lineOut.musicInstruction.musicPlayTimes = -1;
        }
        else if(rxMusic.cap(3) == QObject::tr("暂停"))
        {
            lineOut.musicInstruction.musicPlayTimes = 0;
        }
        else
        {
            lineOut.musicInstruction.musicPlayTimes = rxMusic.cap(3).toInt();
        }

        qDebug() << "rxMusic.cap(3) == " << rxMusic.cap(3);
        qDebug() << "lineOut.musicInstruction.musicPlayTimes =" << lineOut.musicInstruction.musicPlayTimes;
        lineOut.musicInstruction.musicVolume = rxMusic.cap(4).toInt();
        lineOut.musicInstruction.noteStr = rxMusic.cap(6);

        return 1;
    }
    else
    {
        return -1;
    }
}


/*****************************  SET_ODOM  ******************************/
int ProgramRegExp::patSetOdom(QString programStr, Line &lineOut)
{
    lineOut.type = SET_ODOM;

    QRegExp rxSetOdom(str_rx_setOdom);

    bool matchResult;

    if((matchResult = rxSetOdom.exactMatch(programStr)) == true)
    {
        lineOut.odometryResetInstruction.instructionType = SET_ODOM;
        lineOut.odometryResetInstruction.posX = strToDouble(rxSetOdom.cap(2));
        lineOut.odometryResetInstruction.posY = strToDouble(rxSetOdom.cap(5));
        lineOut.odometryResetInstruction.posR = strToDouble(rxSetOdom.cap(8));
        lineOut.odometryResetInstruction.noteStr = strFilt(rxSetOdom.cap(12));
    }
    else
    {
        return -1;
    }
    return 1;
}

/****************************  CHARGING  ***************************/
int ProgramRegExp::patCharging(QString programStr, Line &lineOut)
{
    lineOut.type = CHARGING;

    QRegExp rxCharging(str_rx_charging);
    if(rxCharging.exactMatch(programStr))
    {
        lineOut.chargingInstruction.instructionType = CHARGING;

        if(rxCharging.cap(1) == QObject::tr("TIME"))
        {
            lineOut.chargingInstruction.chargingFinishedType = E_CHARGING_TIME;
            lineOut.chargingInstruction.chargingTime = rxCharging.cap(3).toInt();
            lineOut.chargingInstruction.chargingCaparity = 0;
        }
        else if(rxCharging.cap(1) == QObject::tr("CAPARITY"))
        {
            lineOut.chargingInstruction.chargingFinishedType = E_CHARGING_CAPARITY;
            lineOut.chargingInstruction.chargingCaparity = rxCharging.cap(3).toInt();
            lineOut.chargingInstruction.chargingTime = 0;
        }
        else if(rxCharging.cap(1) == QObject::tr("FIRFIN"))
        {
            lineOut.chargingInstruction.chargingFinishedType = E_CHARGING_FIRST_FINISHED;
            lineOut.chargingInstruction.chargingTime = rxCharging.cap(5).toInt();
            lineOut.chargingInstruction.chargingCaparity = rxCharging.cap(6).toInt();
        }

        lineOut.chargingInstruction.noteStr = rxCharging.cap(8);
    }
    else
    {
        return -1;
    }
    return 1;
}

/*************************  LIFT  ********************************/
int ProgramRegExp::patLift(QString programStr, Line &lineOut)
{
    lineOut.type = LIFT;

    QRegExp rxLift(str_rx_liftMechanism);
    if(rxLift.exactMatch(programStr))
    {
        lineOut.liftMechanismInstruction.instructionType = LIFT;

//        if(rxLift.cap(2) == QObject::tr("General"))
//        {
//            lineOut.liftMechanismInstruction.mechanismType = E_MECHANISM_GENERAL;
//        }
//        else if(rxLift.cap(2) == QObject::tr("Heavy"))
//        {
//            lineOut.liftMechanismInstruction.mechanismType = E_MECHANISM_HEAVY;
//        }

        if(rxLift.cap(3) == QObject::tr("RISE"))
        {
            lineOut.liftMechanismInstruction.liftType = E_LIFT_RISE;
        }
        else if(rxLift.cap(3) == QObject::tr("DOWN"))
        {
            lineOut.liftMechanismInstruction.liftType = E_LIFT_DOWN;
        }
        else if(rxLift.cap(3) == QObject::tr("RIMI"))
        {
            lineOut.liftMechanismInstruction.liftType = E_LIFT_RISE_MIDDLE;
        }
        else if(rxLift.cap(3) == QObject::tr("DOMI"))
        {
            lineOut.liftMechanismInstruction.liftType = E_LIFT_DOWN_MIDDLE;
        }
        else
        {
            lineOut.liftMechanismInstruction.liftType = E_LIFT_ERROR;
        }

        lineOut.liftMechanismInstruction.timeOutValue = rxLift.cap(4).toInt();
        lineOut.liftMechanismInstruction.jmpLbValue = rxLift.cap(7).toInt();
        lineOut.liftMechanismInstruction.noteStr = rxLift.cap(9);
    }
    else
    {
        return -1;
    }

    return 1;
}

int ProgramRegExp::patLoadMap(QString programStr, Line &lineOut)
{
    lineOut.type = LOAD_MAP;
    QRegExp rx_LoadMap(str_rx_loadMap);
    if(rx_LoadMap.exactMatch(programStr))
    {
        lineOut.loadMapInstruction.instructionType = LOAD_MAP;
        lineOut.loadMapInstruction.mapFileName = rx_LoadMap.cap(2).remove(QRegExp("\\s"));
        lineOut.loadMapInstruction.jmpLabel = rx_LoadMap.cap(4);
    }
    else
    {
        return -1;
    }

    return 1;

}

// 匹配解析　CHECKBATTERY  电量检测指令
int ProgramRegExp::patCheckBattery(QString programStr,Line &lineOut)
{
    lineOut.type = CHECK_BATTERY;
    QRegExp rx_checkBattery(str_rx_checkBattery);
    programStr.indexOf(rx_checkBattery);

//    if(rx_checkBattery.exactMatch(programStr))
//    {
//        qDebug()<<rx_checkBattery.capturedTexts();
        lineOut.checkBatteryInstruction.instructionType = CHECK_BATTERY;
        lineOut.checkBatteryInstruction.electricQuantity=rx_checkBattery.cap(2).toInt();
        lineOut.checkBatteryInstruction.labelIndex=rx_checkBattery.cap(5);
//        qDebug()<<rx_checkBattery.cap(1);
//        qDebug()<<rx_checkBattery.cap(2);
//        qDebug()<<rx_checkBattery.cap(3);
//        qDebug()<<rx_checkBattery.cap(4);
//        qDebug()<<rx_checkBattery.cap(5);
//        qDebug()<<rx_checkBattery.cap(6);
//    }
//    else
//    {
//        return -1;
//    }
    return 1;
}
int ProgramRegExp::patWaitCommand(QString programStr,Line &lineOut)
{
    lineOut.type = WAIT_COMAND;
    QRegExp rx_waitCommand(str_rx_waitCommand);

    if(rx_waitCommand.exactMatch(programStr))
    {
        qDebug()<<rx_waitCommand.capturedTexts();
        lineOut.waitCommandInstruction.instructionType=WAIT_COMAND;
        lineOut.waitCommandInstruction.registerIndex=rx_waitCommand.cap(3).toInt();
        lineOut.waitCommandInstruction.waitMaxTime=rx_waitCommand.cap(5).toInt();
        lineOut.waitCommandInstruction.timeOutLabel=rx_waitCommand.cap(8);
    }
    else
    {
        return -1;
    }
    return 1;
}

int ProgramRegExp::patRobotMove(QString programStr, Line &lineOut)
{
    lineOut.type = ROBOT_MOVE;
    QRegExp rx_robotMove(str_rx_RobotMove);

    if(rx_robotMove.exactMatch(programStr))
    {
        qDebug()<< rx_robotMove.capturedTexts();
        lineOut.robotMoveInstruction.instructionType=ROBOT_MOVE;

        if(rx_robotMove.cap(6) == QObject::tr("SERVER"))
        {
            lineOut.robotMoveInstruction.robotMoveBusType = EM_ROBOT_MOVE_BUS_SERVER;
            lineOut.robotMoveInstruction.localIP = rx_robotMove.cap(3);
            lineOut.robotMoveInstruction.serverIP = "192.168.0.0";
        }
        else if(rx_robotMove.cap(6) == QObject::tr("CLIENT"))
        {
            lineOut.robotMoveInstruction.robotMoveBusType = EM_ROBOT_MOVE_BUS_CLIENT;
            lineOut.robotMoveInstruction.serverIP = rx_robotMove.cap(3);
            lineOut.robotMoveInstruction.localIP = "127.0.0.1";
        }

        lineOut.robotMoveInstruction.communicationPort = rx_robotMove.cap(5).toInt();
        lineOut.robotMoveInstruction.sendParameterStr = rx_robotMove.cap(7);
        lineOut.robotMoveInstruction.waitParameterStr = rx_robotMove.cap(8);
        lineOut.robotMoveInstruction.timeOutValue = rx_robotMove.cap(10).toInt();
        lineOut.robotMoveInstruction.jmpLableValue = rx_robotMove.cap(13);
        lineOut.robotMoveInstruction.noteStr = rx_robotMove.cap(14);
    }
    else
    {
        return -1;
    }

    return 1;
}

int ProgramRegExp::patRoller(QString programStr, Line &lineOut)
{
    lineOut.type = ROLLER;

    QRegExp rxRoller(str_rx_Roller);
    if(rxRoller.exactMatch(programStr))
    {
        lineOut.rollerInstruction.instructionType = ROLLER;

//        if(rxRoller.cap(2) == QObject::tr("General"))
//        {
//            lineOut.rollerInstruction.rollerType = E_ROLLER_GENERAL;
//        }
//        else if(rxRoller.cap(2) == QObject::tr("Heavy"))
//        {
//            lineOut.rollerInstruction.rollerType = E_ROLLER_HEAVY;
//        }
//        else
//        {
//            lineOut.rollerInstruction.rollerType = E_ROLLER_ERROR;
//        }

        if(rxRoller.cap(3) == QObject::tr("P"))
        {
            lineOut.rollerInstruction.rollerDirectionType = E_ROLLER_LEFT_LOAD;
        }
        else if(rxRoller.cap(3) == QObject::tr("R"))
        {
            lineOut.rollerInstruction.rollerDirectionType = E_ROLLER_LEFT_DOWNLOAD;
        }
        else if(rxRoller.cap(3) == QObject::tr("A"))
        {
            lineOut.rollerInstruction.rollerDirectionType = E_ROLLER_RIGHT_LOAD;
        }
        else if(rxRoller.cap(3) == QObject::tr("B"))
        {
            lineOut.rollerInstruction.rollerDirectionType = E_ROLLER_RIGHT_DOWNLOAD;
        }

        lineOut.rollerInstruction.timeOutValue = rxRoller.cap(4).toInt();
        lineOut.rollerInstruction.jmpLbValue = rxRoller.cap(7).toInt();
        lineOut.rollerInstruction.noteStr = rxRoller.cap(9);
    }
    else
    {
        return -1;
    }

    return 1;
}

int ProgramRegExp::patVisionRun(QString programStr,Line &lineOut)
{
        lineOut.type = INS_VISION_RUN;
        QString pattern("\\s*([VISIONRUN]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
        QRegExp rx(pattern);
        programStr.indexOf(rx);
        /****************************LABEL*********************************/
        int  li = strToInt(rx.cap(2));
        lineOut.visionRunInstruction.visionIndex = li;
        lineOut.visionRunInstruction.comment = rx.cap(3);
        return 1;
}

int ProgramRegExp::patVisionTrigger(QString programStr, Line &lineOut)
{
    lineOut.type = INS_VISION_TRIGGER;
    QString pattern("\\s*([TRIGGERVISION]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************LABEL*********************************/
    int  li = strToInt(rx.cap(2));
    lineOut.visionTriggerInstruction.visionIndex = li;
    lineOut.visionTriggerInstruction.comment = rx.cap(3);
    return 1;
}

int ProgramRegExp::patVisionGetData(QString programStr, Line &lineOut)
{
    lineOut.type = INS_VISION_GET_DATA;
    QString pattern("\\s*([GETVISIONDATA]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************LABEL*********************************/
    int  li = strToInt(rx.cap(2));
    lineOut.visionGetDataInstruction.visionIndex = li;
    lineOut.visionGetDataInstruction.comment = rx.cap(3);
    return 1;
}

int ProgramRegExp::patVisionClearData(QString programStr, Line &lineOut)
{
    lineOut.type = INS_VISION_CLEAR_DATA;
    QString pattern("\\s*([CLEARVISIONDATA]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************LABEL*********************************/
    int  li = strToInt(rx.cap(2));
    lineOut.visionClearDataInstruction.visionIndex = li;
    lineOut.visionClearDataInstruction.comment = rx.cap(3);
    return 1;
}

int ProgramRegExp::patTrackStart(QString programStr, Line &lineOut)
{
    lineOut.type = INS_TRACK_START;
    QString pattern("\\s*([TRACKSTART]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************LABEL*********************************/
    int  li = strToInt(rx.cap(2));
    lineOut.trackStartInstruction.beltIndex = li;
    lineOut.trackStartInstruction.comment = rx.cap(3);
    return 1;
}

int ProgramRegExp::patTrackEnd(QString programStr, Line &lineOut)
{
    //缺乏严格的语法错误检查
    lineOut.type = INS_TRACK_END;
    QString pattern("\\s*([TRACKEND]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);

    /****************************LABEL*********************************/
    int  li = strToInt(rx.cap(2));
    lineOut.trackEndInstruction.beltIndex = li;
    lineOut.trackEndInstruction.comment = rx.cap(3);
    return 1;

}

int ProgramRegExp::patTrackGetData(QString programStr, Line &lineOut)
{
    //缺乏严格的语法错误检查
    lineOut.type = INS_TRACK_GET_DATA;
    QString pattern("\\s*([GETTRACKDATA]{3})\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************LABEL*********************************/
    int  li = strToInt(rx.cap(2));
    lineOut.trackGetDataInstruction.beltIndex = li;
    lineOut.trackGetDataInstruction.comment = rx.cap(3);
    return 1;
}

int ProgramRegExp::patRegPr(QString programStr, Line &lineOut)
{
    //缺乏严格的语法错误检查//
    lineOut.type = INS_REG_PR;

    QRegExp regExp_prij_const("PR\\[(\\d+),(\\d+)\\]=\\s*(-?\\d*\\.*\\d*)\\s*;\\s*//(.*)");//ok
    QRegExp regExp_pri_pri("PR\\[(\\d+)\\]=\\s*(-?)PR\\[(\\d+)\\]\\s*;\\s*//(.*)");
    QRegExp regExp_pri_minus_pri("PR\\[(\\d+)\\]=\\s*(-?)PR\\[(\\d+)\\]\\s*(-?\\+?)\\s*PR\\[(\\d+)\\]\\s*;\\s*//(.*)");
//    QRegExp regExp_prij_prij("PR\\[(\\d+),(\\d+)\\]=\\s*(-*)PR\\[(\\d+),(\\d+)\\]\\s*;\\s*//(.*)");
    QRegExp regExp_prij_minus_prij("PR\\[(\\d+),(\\d+)\\]=\\s*(-*)PR\\[(\\d+),(\\d+)\\]\\s*(-?\\+?)\\s*PR\\[(\\d+),(\\d+)\\]\\s*;\\s*//(.*)");
    QRegExp regExp_prij_prij_const("PR\\[(\\d+),(\\d+)\\]=\\s*(-*)PR\\[(\\d+),(\\d+)\\]\\s*(-?\\+?\\d*\\.*\\d*)\\s*;\\s*//(.*)");
    QRegExp regExp_pri_LPS("PR\\[(\\d+)\\]=\\s*LPOS\\s*;\\s*//(.*)");
    QRegExp regExp_pri_JPS("PR\\[(\\d+)\\]=\\s*JPOS\\s*;\\s*//(.*)");

//    programStr.indexOf(rx);

//    bool isMatch=regExp_prij_const.exactMatch(programStr);

//    if(false==isMatch )
//    {
//        qDebug()<<regExp_prij_const.cap(0)<<regExp_prij_const.cap(1)<<regExp_prij_const.cap(2)<<regExp_prij_const.cap(3)<<regExp_prij_const.cap(4)<<regExp_prij_const.cap(5)
//                  <<regExp_prij_const.cap(6)<<regExp_prij_const.cap(7)<<regExp_prij_const.cap(8)<<regExp_prij_const.cap(9);
//        return -1;
//    }
    if(regExp_pri_minus_pri.exactMatch(programStr))//
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRI_MINUS_PRI;

        lineOut.prRegisterInstruction.left_index_i= regExp_pri_minus_pri.cap(1).toInt();
        lineOut.prRegisterInstruction.right_index_i= regExp_pri_minus_pri.cap(3).toInt();
        if("-"==regExp_pri_minus_pri.cap(2))
        {
           lineOut.prRegisterInstruction.right_operate1=-1;
        }
        else
        {
            lineOut.prRegisterInstruction.right_operate1=1;
        }
        lineOut.prRegisterInstruction.right2_index_i= regExp_pri_minus_pri.cap(5).toInt();
        if("-"==regExp_pri_minus_pri.cap(4))
        {
           lineOut.prRegisterInstruction.right_operate2=-1;
        }
        else
        {
            lineOut.prRegisterInstruction.right_operate2=1;
        }

        lineOut.prRegisterInstruction.comment= regExp_pri_minus_pri.cap(6);
        return 1;
    }
    else if(regExp_prij_minus_prij.exactMatch(programStr))
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRIJ_MINUS_PRIJ;

        lineOut.prRegisterInstruction.left_index_i= regExp_prij_minus_prij.cap(1).toInt();
        lineOut.prRegisterInstruction.left_index_j= regExp_prij_minus_prij.cap(2).toInt();
        lineOut.prRegisterInstruction.right_index_i= regExp_prij_minus_prij.cap(4).toInt();
        lineOut.prRegisterInstruction.right_index_j= regExp_prij_minus_prij.cap(5).toInt();
        if("-"==regExp_prij_minus_prij.cap(3))
        {
           lineOut.prRegisterInstruction.right_operate1=-1;
        }
        else
        {
            lineOut.prRegisterInstruction.right_operate1=1;
        }
        lineOut.prRegisterInstruction.right2_index_i= regExp_prij_minus_prij.cap(7).toInt();
        lineOut.prRegisterInstruction.right2_index_j= regExp_prij_minus_prij.cap(8).toInt();
        if("-"==regExp_prij_minus_prij.cap(6))
        {
           lineOut.prRegisterInstruction.right_operate2=-1;
        }
        else
        {
            lineOut.prRegisterInstruction.right_operate2=1;
        }

        lineOut.prRegisterInstruction.comment= regExp_prij_minus_prij.cap(9);
        return 1;
    }
    else if(regExp_prij_prij_const.exactMatch(programStr))
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRIJ_MINUS_CONST;

        lineOut.prRegisterInstruction.left_index_i= regExp_prij_prij_const.cap(1).toInt();
        lineOut.prRegisterInstruction.left_index_j= regExp_prij_prij_const.cap(2).toInt();
        lineOut.prRegisterInstruction.right_index_i= regExp_prij_prij_const.cap(4).toInt();
        lineOut.prRegisterInstruction.right_index_j= regExp_prij_prij_const.cap(5).toInt();
        if("-"==regExp_prij_prij_const.cap(3))
        {
           lineOut.prRegisterInstruction.right_operate1=-1;
        }
        else
        {
            lineOut.prRegisterInstruction.right_operate1=1;
        }
        lineOut.prRegisterInstruction.constValue= regExp_prij_prij_const.cap(6).toDouble();


        lineOut.prRegisterInstruction.comment= regExp_prij_prij_const.cap(7);
        return 1;
    }
    else if(regExp_prij_const.exactMatch(programStr))
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRIJ_CONST;
//        lineOut.prRegisterInstruction.isSingleValue=true;
        lineOut.prRegisterInstruction.left_index_i= regExp_prij_const.cap(1).toInt();
        lineOut.prRegisterInstruction.left_index_j= regExp_prij_const.cap(2).toInt();
//        lineOut.prRegisterInstruction.sourceValueType= 0;
//        lineOut.prRegisterInstruction.sourceValueIndex= 0;
        lineOut.prRegisterInstruction.constValue= regExp_prij_const.cap(3).toDouble();
        lineOut.prRegisterInstruction.comment= regExp_prij_const.cap(4);
        return 1;
    }
    else if(regExp_pri_pri.exactMatch(programStr))
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRI_PRI;

        lineOut.prRegisterInstruction.left_index_i= regExp_pri_pri.cap(1).toInt();
        lineOut.prRegisterInstruction.right_index_i= regExp_pri_pri.cap(3).toInt();
        if("-"==regExp_pri_pri.cap(2))
        {
           lineOut.prRegisterInstruction.right_operate1=-1;
        }
        else
        {
            lineOut.prRegisterInstruction.right_operate1=1;
        }

        lineOut.prRegisterInstruction.comment= regExp_pri_pri.cap(4);
        return 1;
    }
    else if(regExp_pri_LPS.exactMatch(programStr))
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRI_LPS;
        lineOut.prRegisterInstruction.left_index_i= regExp_pri_LPS.cap(1).toInt();
        lineOut.prRegisterInstruction.comment= regExp_pri_LPS.cap(2);
        return 1;
    }
    else if(regExp_pri_JPS.exactMatch(programStr))
    {
        lineOut.prRegisterInstruction.instructionType=E_PR_INS_TYPE_PRI_JPS;
        lineOut.prRegisterInstruction.left_index_i= regExp_pri_JPS.cap(1).toInt();
        lineOut.prRegisterInstruction.comment= regExp_pri_JPS.cap(2);
        return 1;
    }
    else
    {
        qDebug()<<regExp_pri_pri.exactMatch(programStr);
        qDebug()<<"error,PR指令正则表达式匹配失败 "<<programStr;
        qDebug()<<regExp_pri_pri<<regExp_pri_pri.cap(0)<<regExp_pri_pri.cap(1)<<regExp_pri_pri.cap(2)<<regExp_pri_pri.cap(3)<<regExp_pri_pri.cap(4)<<regExp_pri_pri.cap(5)
                  <<regExp_pri_pri.cap(6)<<regExp_pri_pri.cap(7)<<regExp_pri_pri.cap(8)<<regExp_pri_pri.cap(9);
        return -1;
    }

}

int ProgramRegExp::patRegPl(QString programStr, Line &lineOut)
{

    QRegExp rxPl("PL\\[(\\d+)\\]=(\\[.*\\]);\\s*//(.*)");
    if(rxPl.exactMatch(programStr))
    {
        lineOut.type = INS_REG_PL;
        lineOut.plRegisterInstruction.plIndex=rxPl.cap(1).toInt();
        lineOut.plRegisterInstruction.valueExpress=rxPl.cap(2);
        lineOut.plRegisterInstruction.comment=rxPl.cap(3);

    }
    else
    {
        return -1;
    }
    return 1;

}

int ProgramRegExp::patWeldStart(QString programStr, Line &lineOut)
{
    lineOut.type = INS_WELD_START;

        QString pattern("Weld\\sStart\\[(\\d+),(\\d+)\\];\\s*//(.*)");
        QRegExp rxRoller(pattern);

        //电流模式下
        QString pattern1("Weld\\sStart\\[(\\d+),(\\d+).*[V],(\\d+).*[A]\\];\\s*//(.*)");
        QRegExp rxRoller1(pattern1);

        //存在送丝速度模式下
        QString pattern2("Weld\\sStart\\[(\\d+),(\\d+).*[V],(\\d+).*[mm/sec]\\];\\s*//(.*)");
        QRegExp rxRoller2(pattern2);

        if(rxRoller.exactMatch(programStr))
        {
            lineOut.weldStartInstruction.weldType=E_WELD_TYPE_COMMON;
            lineOut.weldStartInstruction.weldPropertyIndex=rxRoller.cap(1).toInt();
            lineOut.weldStartInstruction.weldConditionIndex=rxRoller.cap(2).toInt();
            lineOut.weldStartInstruction.comment=rxRoller.cap(3);

        }
        else if(rxRoller1.exactMatch(programStr)){
            lineOut.weldStartInstruction.weldType=E_WELD_TYPE_AMP;
            lineOut.weldStartInstruction.weldPropertyIndex=rxRoller1.cap(1).toInt();
            lineOut.weldStartInstruction.weldVoltage = rxRoller1.cap(2).toDouble();
            lineOut.weldStartInstruction.weldAmp = rxRoller1.cap(3).toDouble();
            lineOut.weldStartInstruction.comment=rxRoller1.cap(4);
        }
        else if(rxRoller2.exactMatch(programStr)){
            lineOut.weldStartInstruction.weldType=E_WELD_TYPE_SPEED;
            lineOut.weldStartInstruction.weldPropertyIndex=rxRoller2.cap(1).toInt();
            lineOut.weldStartInstruction.weldVoltage = rxRoller2.cap(2).toDouble();
            lineOut.weldStartInstruction.weldSpeed = rxRoller2.cap(3).toDouble();
            lineOut.weldStartInstruction.comment=rxRoller2.cap(4);
        }
        else
        {
            return -1;
        }

        return 1;
}

int ProgramRegExp::patWeldEnd(QString programStr, Line &lineOut)
{
    lineOut.type = INS_WELD_END;

        QString pattern("Weld\\sEnd\\[(\\d+),(\\d+)\\];\\s*//(.*)");
        QRegExp rxRoller(pattern);

        //电流模式下
        QString pattern1("Weld\\sEnd\\[(\\d+),(\\d+).*[V],(\\d+).*[A],(\\d+.{0,1}\\d*).*[sec]\\];\\s*//(.*)");
        QRegExp rxRoller1(pattern1);

        if(rxRoller.exactMatch(programStr))
        {
            lineOut.weldEndInstruction.weldType=E_WELDEND_TYPE_COMMON;
            lineOut.weldEndInstruction.weldPropertyIndex=rxRoller.cap(1).toInt();
            lineOut.weldEndInstruction.weldConditionIndex=rxRoller.cap(2).toInt();
            lineOut.weldEndInstruction.comment=rxRoller.cap(3);

        }
        else if(rxRoller1.exactMatch(programStr)){
            lineOut.weldEndInstruction.weldType=E_WELDEND_TYPE_AMP;
            lineOut.weldEndInstruction.weldPropertyIndex=rxRoller1.cap(1).toInt();
            lineOut.weldEndInstruction.weldVoltage = rxRoller1.cap(2).toDouble();
            lineOut.weldEndInstruction.weldAmp = rxRoller1.cap(3).toDouble();
            lineOut.weldEndInstruction.weldTime = rxRoller1.cap(4).toDouble();
            lineOut.weldEndInstruction.comment=rxRoller1.cap(5);

        }
        else
        {
            return -1;
        }

        return 1;

}
int ProgramRegExp::patWeave(QString programStr, Line &lineOut)
{
    lineOut.type = INS_WEAVE;

     QString pattern("Weave\\s*\\[(\\d+)\\];\\s*//(.*)");
     QRegExp rxRoller(pattern);

     //电流模式下
     QString pattern1("Weave\\s(\\d+)\\s\\[(\\d+)Hz,(\\d+)mm,(\\d+.{0,1}\\d*)sec,(\\d+.{0,1}\\d*)sec\\];\\s*//(.*)");
     QRegExp rxRoller1(pattern1);

     if(rxRoller.exactMatch(programStr))
     {
         lineOut.weaveInstruction.weaveType=E_WEAVE_TYPE_COMMON;
         lineOut.weaveInstruction.weavePropertyIndex=0;
         lineOut.weaveInstruction.weaveConditionIndex=rxRoller.cap(1).toInt();
         lineOut.weaveInstruction.comment=rxRoller.cap(2);

     }
     else if(rxRoller1.exactMatch(programStr))
     {
         lineOut.weaveInstruction.weaveType=E_WEAVE_TYPE_HZ;
         lineOut.weaveInstruction.weavePropertyIndex=rxRoller1.cap(1).toInt();
         lineOut.weaveInstruction.weaveHz = rxRoller1.cap(2).toDouble();
         lineOut.weaveInstruction.weaveAmplitude = rxRoller1.cap(3).toDouble();
         lineOut.weaveInstruction.weaveLeftStay = rxRoller1.cap(4).toDouble();
         lineOut.weaveInstruction.weaveRightStay=rxRoller1.cap(5).toDouble();
         lineOut.weaveInstruction.comment=rxRoller1.cap(6);
     }
     else
     {
         return -1;
     }

     return 1;

}

int ProgramRegExp::patWeaveEnd(QString programStr, Line &lineOut)
{   lineOut.type = INS_WEAVE_END;

    QString pattern("Weave\\s*End;\\s*//(.*)");
    QRegExp rxRoller(pattern);

    //电流模式下
    QString pattern1("Weave\\sEnd\\s\\[(\\d+)\\];\\s*//(.*)");
    QRegExp rxRoller1(pattern1);

    if(rxRoller.exactMatch(programStr))
    {
        lineOut.weaveEndInstruction.weaveEndType=E_WEAVEEND_TYPE_COMMON;
        lineOut.weaveEndInstruction.comment=rxRoller.cap(1);

    }
    else if(rxRoller1.exactMatch(programStr)){
        lineOut.weaveEndInstruction.weaveEndType=E_WEAVEEND_TYPE_PROPERTY;
        lineOut.weaveEndInstruction.weavePropertyIndex=rxRoller1.cap(1).toInt();
        lineOut.weaveEndInstruction.comment=rxRoller1.cap(2);

    }
    else
    {
        return -1;
    }

    return 1;

}

int ProgramRegExp::patTrackWeldEnd(QString programStr,Line &lineOut)
{   lineOut.type = INS_TRACKWELD_END;

    QString pattern("Track\\sWeld\\sEnd;\\s*//(.*)");
    QRegExp rxRoller(pattern);



    if(rxRoller.exactMatch(programStr))
    {

        lineOut.trackWeldEndInstruction.comment=rxRoller.cap(1);

    }

    else
    {
        return -1;
    }

    return 1;

}
//新指令20191130 ZHUHT
int ProgramRegExp::patWatchDI(QString programStr, Line &lineOut)
{   lineOut.type = INS_WATCHDI;
     //时间模式下
    QString pattern("Watch\\sDI\\[(\\d+)\\]\\=(\\w+)\\s(\\d+.{0,1}\\d*)\\ssec\\sDO\\[(\\d+)\\]\\=(\\w+);\\s*//(.*)");
    QRegExp rxRoller(pattern);

    //计数器模式下
    QString pattern1("Watch\\sDI\\[(\\d+)\\]\\=(\\w+)\\sR\\[(\\d+)\\]\\ssec\\sDO\\[(\\d+)\\]\\=(\\w+);\\s*//(.*)");
    QRegExp rxRoller1(pattern1);

    if(rxRoller.exactMatch(programStr))
    {
        lineOut.watchDIInstruction.watchDITyde=E_WATCHDI_TYPE_TIME;
        lineOut.watchDIInstruction.dIIndex=rxRoller.cap(1).toInt();
        lineOut.watchDIInstruction.dISwitch=rxRoller.cap(2);
        lineOut.watchDIInstruction.watchTime=rxRoller.cap(3).toDouble();
        lineOut.watchDIInstruction.dOIndex=rxRoller.cap(4).toInt();
        lineOut.watchDIInstruction.dOSwitch=rxRoller.cap(5);
        lineOut.watchDIInstruction.comment=rxRoller.cap(6);

    }
    else if(rxRoller1.exactMatch(programStr)){
        lineOut.watchDIInstruction.watchDITyde=E_WATCHDI_TYPE_COUNTER;
        lineOut.watchDIInstruction.dIIndex=rxRoller1.cap(1).toInt();
        lineOut.watchDIInstruction.dISwitch=rxRoller1.cap(2);
        lineOut.watchDIInstruction.counterIndex=rxRoller1.cap(3).toInt();
        lineOut.watchDIInstruction.dOIndex=rxRoller1.cap(4).toInt();
        lineOut.watchDIInstruction.dOSwitch=rxRoller1.cap(5);
        lineOut.watchDIInstruction.comment=rxRoller1.cap(6);

    }
    else
    {
        return -1;
    }

    return 1;

}

int ProgramRegExp::patLaserCameraFetchPoint(QString programStr, Line &lineOut)
{
    lineOut.type = INS_LASER_CAMERA_FETCHPOINT;
    QString pattern("^\\s*RECORD_LASERCAMERA\\s+PR\\[(\\d*)\\]\\s*;//(.*)");
    QRegExp rx_fetchPoint(pattern);

    if(rx_fetchPoint.exactMatch(programStr))
    {
        qDebug()<< rx_fetchPoint.capturedTexts();
        lineOut.laserCameraPointFetchInstruction.prRegisterIndex = rx_fetchPoint.cap(1).toInt();
        lineOut.laserCameraPointFetchInstruction.comment = rx_fetchPoint.cap(2);
    }
    else
    {
        return -1;
    }

    return 1;
}

int ProgramRegExp::patLaserCameraControl(QString programStr, Line &lineOut)
{
    lineOut.type = INS_LASER_CAMERA_CTRL;
    QString pattern("^\\s*LASERCAMERA_CTRL\\s+([ONF]{2,3})\\s+JOB\\[(\\d*)\\]\\s*;//(.*)");
    QRegExp rx_fetchPoint(pattern);

    if(rx_fetchPoint.exactMatch(programStr))
    {
        qDebug()<< rx_fetchPoint.capturedTexts();
        if("ON"==rx_fetchPoint.cap(1))
        {
            lineOut.laserCameraCtrlInstruction.isOn = true;
        }
        else
        {
            lineOut.laserCameraCtrlInstruction.isOn = false;
        }
        lineOut.laserCameraCtrlInstruction.jobIndex=rx_fetchPoint.cap(2).toInt();
        lineOut.laserCameraCtrlInstruction.noteStr = rx_fetchPoint.cap(3);
    }
    else
    {
        return -1;
    }

    return 1;
}

int ProgramRegExp::patLaserCameraTrack(QString programStr, Line &lineOut)
{
    lineOut.type = INS_LASER_CAMERA_TRACK;
    QString pattern("^\\s*LASERCAMERA_TRACK\\s+([ONF]{2,3})\\s*;//(.*)");
    QRegExp rx_fetchPoint(pattern);

    if(rx_fetchPoint.exactMatch(programStr))
    {
        qDebug()<< rx_fetchPoint.capturedTexts();
        if("ON"==rx_fetchPoint.cap(1))
        {
            lineOut.laserCameraTrackInstruction.isStart = true;
        }
        else
        {
            lineOut.laserCameraTrackInstruction.isStart  = false;
        }
        lineOut.laserCameraTrackInstruction.commentStr = rx_fetchPoint.cap(2);
    }
    else
    {
        return -1;
    }

    return 1;
}

int ProgramRegExp::patLaserScan(QString programStr, Line &lineOut)
{
       lineOut.type = INS_LASER_SCAN;

       QString pattern("LASERSCAN\\s(.*);\\s*/?/?(.*)");
       QRegExp rxRoller(pattern);


       if(rxRoller.exactMatch(programStr))
       {
           if("START"==rxRoller.cap(1))
           {
               lineOut.laserScanIns.isStart=true;
           }
           else if("END"==rxRoller.cap(1))
           {
               lineOut.laserScanIns.isStart=false;
           }
           else
           {
               qDebug()<<"error,,,patLaserScan";
               return 0;
           }
           lineOut.laserScanIns.noteStr=rxRoller.cap(2);

       }
       else
       {
           return -1;
       }

       return 1;
}

int ProgramRegExp::patBufferMove(QString programStr, Line &lineOut)
{
       lineOut.type = INS_BUFFER_MOVE;

//       QString pattern("BUFFERMOVE\\[(.*)\\];\\s*/?/?(.*)");
//       QString pattern("BUFFERMOVE\\s*(\\d*)mm/sec;\\s*//(.*)");
       QString pattern("BUFFERMOVE\\s*(\\d*)mm/sec\\s*CONST\\s*;\\s*//(.*)");
       QRegExp rxRoller(pattern);

       QString pattern_ori("BUFFERMOVE\\s*(\\d*)mm/sec\\s*ORI\\s*P\\[(\\d*)\\]\\s*P\\[(\\d*)\\]\\s*P\\[(\\d*)\\]\\s*;\\s*//(.*)");
       QRegExp rxRoller_ori(pattern_ori);


       if(rxRoller.exactMatch(programStr))
       {
           lineOut.bufferMoveIns.velocity=rxRoller.cap(1).toDouble();
           lineOut.bufferMoveIns.noteStr=rxRoller.cap(2);
           lineOut.bufferMoveIns.type=E_BUFFER_MOVE_CONST;

       }
       else if(rxRoller_ori.exactMatch(programStr))
       {
           lineOut.bufferMoveIns.velocity=rxRoller_ori.cap(1).toDouble();
           lineOut.bufferMoveIns.noteStr=rxRoller_ori.cap(5);
           lineOut.bufferMoveIns.type=E_BUFFER_MOVE_ORI;

           lineOut.bufferMoveIns.oriPointIndex_1=rxRoller_ori.cap(2).toInt();
           lineOut.bufferMoveIns.oriPointIndex_2=rxRoller_ori.cap(3).toInt();
           lineOut.bufferMoveIns.oriPointIndex_3=rxRoller_ori.cap(4).toInt();

       }
       else
       {
           qDebug()<<"error,,,patBufferMove";
           return -1;
       }

       return 1;
}
int ProgramRegExp::patTrackWeldTast(QString programStr,Line &lineOut)
{   lineOut.type = INS_TRACKWELD_TAST;

    QString pattern("Track\\sWeld\\sTAST\\s\\[(\\d+)\\];\\s*//(.*)");
    QRegExp rxRoller(pattern);


    if(rxRoller.exactMatch(programStr))
    {
        lineOut.trackWeldTastInstruction.trackWeldPropertyIndex=rxRoller.cap(1).toInt();
        lineOut.trackWeldTastInstruction.comment=rxRoller.cap(2);

    }
    else
    {
        return -1;
    }

    return 1;

}

int ProgramRegExp::patGripper(QString programStr, Line &lineOut)
{

    lineOut.type = GRIPPER;

    QRegExp rx1(str_rx_gripper_active);
    QRegExp rx2(str_rx_gripper_set);
    QRegExp rx3(str_rx_gripper_wait);

    programStr.indexOf(rx1);
    programStr.indexOf(rx2);
    programStr.indexOf(rx3);

    QString("%1%2").arg("\\s*(ActiveGripper)\\s*(,)\\s*(LBL)\\s*\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]").arg(srt_rx_notes);
    QString("%1%2").arg("\\s*(SetGripper)\\s*(\\d+)\\s*(\\d+)\\s*(\\d+)").arg(srt_rx_notes);
    QString("%1%2").arg("\\s*(WaitGripper)\\s*(,)\\s*(TIMEOUT)\\s*(\\d+\\.?\\d*)\\s*(LBL)\\s*\\[([R]?\\[?\\d+\\]?)\\s*:?\\s*([^:]{0,16})\\]").arg(srt_rx_notes);

    bool match;

    if((match = rx1.exactMatch(programStr)) == true)
    {
        lineOut.gripperInstruct.gripperType = ENUM_GRIPPER_ACTIVE;

        QString str4 = strFilt(rx1.cap(4));

        int lblValue = strToInt(rx1.cap(4));

        if("R[]" == str4)
        {
            lineOut.gripperInstruct.type = INDIRECT;
        }
        else
        {
            lineOut.gripperInstruct.type = DIRECT;
        }

         lineOut.gripperInstruct.i = lblValue;

    }
    else if((match = rx2.exactMatch(programStr)) == true)
    {
        lineOut.gripperInstruct.gripperType = ENUM_GRIPPER_SET;

        int position = strToInt(rx2.cap(2));
        int speed = strToInt(rx2.cap(3));
        int force = strToInt(rx2.cap(4));

        lineOut.gripperInstruct.gripperPosition = position;
        lineOut.gripperInstruct.gripperSpeed = speed;
        lineOut.gripperInstruct.gripperForce = force;
    }
    else if((match = rx3.exactMatch(programStr)) == true)
    {
        lineOut.gripperInstruct.gripperType = ENUM_GRIPPER_WAIT;
        float waitTime = (float)strToDouble(rx3.cap(4));
        lineOut.gripperInstruct.waitTime = waitTime;
        QString str6 = strFilt(rx3.cap(6));
        if("R[]" == str6)
        {
            lineOut.gripperInstruct.type = INDIRECT;
        }
        else
        {
            lineOut.gripperInstruct.type = DIRECT;
        }

        int lblValue = strToInt(rx3.cap(6));

        lineOut.gripperInstruct.i = lblValue;
    }

    return 1;
}



/***************JUMP指令处理函数**********************/
int ProgramRegExp::patJump(QString programStr,Line &lineOut)
{
    lineOut.type = JUMP;
    QString pattern("\\s*([JMP]{3})\\s*([LBL]+)\\[([R]?\\[?[0-9:\\w]+\\]?)\\].*(//)\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************JMP*********************************/
    QString r = strFilt(rx.cap(3));
    if(r=="R[]")
    {
        lineOut.jump.type = INDIRECT;
        lineOut.jump.jumpLabelStr = QString::number(strToInt(rx.cap(3)));
    }
    else
    {
        lineOut.jump.type = DIRECT;
        lineOut.jump.jumpLabelStr = rx.cap(3);
    }

    lineOut.jump.comment = rx.cap(5);
    return 1;
}

/***************LABEL指令处理函数****************＊****/
int ProgramRegExp::patLabel(QString programStr,Line &lineOut)
{
    lineOut.type = LABEL;
    QString pattern("\\s*([LBL]{3})\\[([R]?\\[?\\S+\\]?)\\s*:?\\s*([^:]{0,16})\\].*(//)\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /****************************LABEL*********************************/
    lineOut.label.labelStr = rx.cap(2);
    lineOut.label.comment = rx.cap(5);
    return 1;

}

/*********＊******IO指令处理函数*******＊*********＊***/
int ProgramRegExp::patIo(QString programStr,Line &lineOut)
{
    lineOut.type = IO;
    QString pattern("\\s*([ARDGO]{1,2})\\[([R]?\\[?\\d+\\]?)\\]\\s*=\\s*(\\w*)\\s*,?\\s*\\[?([R]?\\[?\\d*\\.?\\d*\\s*\\w*)\\]?\\]?\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);
    /********IO_TYPE****************/
    if(rx.cap(1) == "R")
    {
        if(rx.cap(3) == "DI")
        {
            lineOut.io.type = R_DI;
        }
        else if(rx.cap(3) == "RI")
        {
            lineOut.io.type = R_RI;
        }
        else if(rx.cap(3) == "AI")
        {
            lineOut.io.type = R_AI;
        }
        else if(rx.cap(3) == "GI")
        {
            lineOut.io.type = R_GI;
        }
    }
    else if(rx.cap(1) == "DO")
    {
        if(rx.cap(3) == "ON")
        {
            lineOut.io.type = DO_ON;
        }
        else if(rx.cap(3) == "OFF")
        {
            lineOut.io.type = DO_OFF;
        }
        else if(rx.cap(3) == "PULSE")
        {
            lineOut.io.type = DO_PULSE_WIDTH;
            float width = strToDouble(rx.cap(4));
            lineOut.io.width = width;
        }
        else if(rx.cap(3) == "R")
        {
            lineOut.io.type = DO_R;
        }
    }
    else if(rx.cap(1) == "RO")
    {
        if(rx.cap(3) == "ON")
        {
            lineOut.io.type = RO_ON;
        }
        else if(rx.cap(3) == "OFF")
        {
            lineOut.io.type = RO_OFF;
        }
        else if(rx.cap(3) == "PULSE")
        {
            lineOut.io.type = RO_PULSE_WIDTH;
            float width = strToDouble(rx.cap(4));
            lineOut.io.width = width;
        }
        else if(rx.cap(3) == "R")
        {
            lineOut.io.type = RO_R;
        }
    }
    else if(rx.cap(1) == "AO")
    {
        if(rx.cap(3) == "R")
        {
            lineOut.io.type = AO_R;
        }
        else
        {
            lineOut.io.type = AO_CONST;
        }
    }
    else if(rx.cap(1) == "GO")
    {
        if(rx.cap(3) == "R")
        {
            lineOut.io.type = GO_R;
        }
        else
        {
            lineOut.io.type = GO_CONST;
        }
    }
    QString front_str = strFilt(rx.cap(2));
    if(front_str == "R[]")
    {
        lineOut.io.front_addtype = INDIRECT;
    }
    else
    {
        lineOut.io.front_addtype = DIRECT;
    }
    int front_val = strToInt(rx.cap(2));
    lineOut.io.front_val = front_val;
    QString back_str = strFilt(rx.cap(4));
    if(back_str == "R[]")
    {
        lineOut.io.back_addtype = INDIRECT;
    }
    else
    {
        lineOut.io.back_addtype = DIRECT;
    }
    int back_val;
    if(lineOut.io.type == AO_CONST ||
            lineOut.io.type == GO_CONST ||
            lineOut.io.type == DO_PULSE_WIDTH ||
            lineOut.io.type == RO_PULSE_WIDTH)
    {
        back_val = strToInt(rx.cap(3));
    }
    else
    {
        back_val = strToInt(rx.cap(4));
    }
    lineOut.io.back_val = back_val;
    return 1;
}

/***************CALL指令处理函数****************＊*****/
int ProgramRegExp::patCall(QString programStr,Line &lineOut)
{
    lineOut.type = CALL;
    QString pattern("\\s*([CALL]{4})\\s*(\\S*)\\s*;(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);

    /****************************CALL*********************************/
    lineOut.call.programName = rx.cap(2);
    return 1;
}

/***************IF指令处理函数****************＊*＊****/
int ProgramRegExp::patIf(QString programStr, int lineIndex, Program &programOut)
{
    programOut[lineIndex].type = IF;
    QString pattern("\\s*([IF]{2})\\s*(.*)\\s*,\\s*(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);

    int protype = patExtractInstructionType(rx.cap(3));
    if(protype == CALL)
    {
        programOut[lineIndex].ifIns.processType = CALLING;
        patCall(rx.cap(3),programOut[lineIndex]);
        programOut[lineIndex].type = IF;
        programOut[lineIndex].ifIns.callProcess = programOut[lineIndex].call;
    }
    else if(protype == JUMP)
    {
        programOut[lineIndex].ifIns.processType = JMP;
        patJump(rx.cap(3),programOut[lineIndex]);
        programOut[lineIndex].type = IF;
        programOut[lineIndex].ifIns.jumpProcess = programOut[lineIndex].jump;
    }
    /********************************************************/
    QStringList strListand,strListor;
    strListand = rx.cap(2).split("AND");
    strListor = rx.cap(2).split("OR");
    /********************************************************/
//    QString pattern2("\\s*(\\w+)\\[([R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*(\\w*)\\[?(R?\\[?\\d*\\]?)\\]?\\s*");
//    QString pattern2("\\s*(\\w+)\\[([R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*(\\w*)(.*)\\s*");

    QString pattern2("\\s*([RAOIGDRSUPLTME]{1,5})\\s*\\[([R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*([ONFDIRSUPL]{0,3})\\s*(.*)");
    QRegExp rx2(pattern2);
    if(strListand.size() == 1 && strListor.size() == 1)
    {
        programOut[lineIndex].ifIns.andOrType = NEITHER;
        programOut[lineIndex].ifIns.condition.resize(1);
//        qDebug()<<"ifInstruction split0-------rx.cap(2)----------------:"<<rx.cap(2);
        rx.cap(2).indexOf(rx2);
        //variableType
//        qDebug()<<"ifInstruction split1-----------------------:"<<rx2.cap(1);
        QString vartype = strFilt(rx2.cap(1));
//        qDebug()<<"ifInstruction split２-----------------------:"<<vartype;
        if(vartype == "R")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_R;
        }
        else if(vartype == "AO")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_AO;
        }
        else if(vartype == "AI")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_AI;
        }
        else if(vartype == "GO")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_GO;
        }
        else if(vartype == "GI")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_GI;
        }
        else if(vartype == "DO")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_DO;
        }
        else if(vartype == "DI")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_DI;
        }
        else if(vartype == "RO")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_RO;
        }
        else if(vartype == "RI")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_RI;
        }
        else if(vartype == "SO")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_SO;
        }
        else if(vartype == "SI")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_SI;
        }
        else if(vartype == "UO")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_UO;
        }
        else if(vartype == "UI")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_UI;
        }
        else if(vartype == "PL")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_PL;
        }
        else if(vartype == "TIMER")
        {
            programOut[lineIndex].ifIns.condition[0].variableType = IF_TIMER;
        }
        QString varType2 = strFilt(rx2.cap(2));
        if("R[]" == varType2)
        {
            programOut[lineIndex].ifIns.condition[0].front_addType = INDIRECT;
        }
        else
        {
            programOut[lineIndex].ifIns.condition[0].front_addType = DIRECT;
        }
        //valuetype
        QString valtype = strFilt(rx2.cap(4));
//        qDebug()<<"ifInstruction split４-------rx.cap(2)----------------:"<<rx2.cap(4);
//        qDebug()<<"ifInstruction split５-------rx.cap(2)----------------:"<<valtype;
        if(valtype == "R")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_R;
        }
        else if(valtype == "ON")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_ON;
//            qDebug()<<"ifInstruction programOut[lineNum].ifIns.condition[0].valueType-------IF_ON---------:"
//                   <<programOut[lineNum].ifIns.condition[0].valueType;
        }
        else if(valtype == "OFF")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_OFF;
//            qDebug()<<"ifInstruction programOut[lineNum].ifIns.condition[0].valueType-------IF_OFF---------:"
//                   <<programOut[lineNum].ifIns.condition[0].valueType;
        }
        else if(valtype == "DO")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_DO;
        }
        else if(valtype == "DI")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_DI;
        }
        else if(valtype == "RO")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_RO;
        }
        else if(valtype == "RI")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_RI;
        }
        else if(valtype == "SO")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_SO;
        }
        else if(valtype == "SI")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_SI;
        }
        else if(valtype == "UO")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_UO;
        }
        else if(valtype == "UI")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_UI;
        }
        else if(valtype == "PL")
        {
            programOut[lineIndex].ifIns.condition[0].valueType = IF_PL;
        }
        else
        {
            if(rx2.cap(5).contains(","))
            {

            }
            else
            {
                programOut[lineIndex].ifIns.condition[0].valueType = IF_CONST;
                programOut[lineIndex].ifIns.condition[0].value_i = strToDouble(rx2.cap(4));
            }
        }


//        qDebug() << "***cap1**"<<rx2.cap(1)<<"**cap2****"<<rx2.cap(2)<<
//                    "**cap3***"<<rx2.cap(3)<<"**cap4***"<<rx2.cap(4)<<endl;

        QString cap5Value = rx2.cap(5);
        QString valType1 = strFilt(cap5Value);
//        qDebug() << __FUNCTION__<<"******"<<__LINE__<<"***cap5Value****"<<cap5Value<<"**valType1***"<<
//                    valType1<<"****int**"<<strToInt(cap5Value)<<endl;
        if(!cap5Value.isEmpty())
        {
            if(cap5Value.contains(","))
            {
                if(2 == cap5Value.count(","))
                {
                    cap5Value = cap5Value.remove(" ");
                    cap5Value = cap5Value.remove("[");
                    cap5Value = cap5Value.remove("]");
                    QStringList plList = cap5Value.split(",");

                    programOut[lineIndex].ifIns.condition[0].valueType = IF_PL_IJK;
                    for(int j = 0; j < plList.size();j++)
                    {
                        if("*" == plList[j])
                        {
                            plList[j] = "100000";
                        }
                        else if("2-0" == plList[j])
                        {
                            plList[j] = "1000";
                        }
                        else if("2-1" == plList[j])
                        {
                            plList[j] = "1001";
                        }
                    }

                    QString str_i,str_j,str_k;

                    str_i = plList[0];
                    str_j = plList[1];
                    str_k = plList[2];

                    if(str_i.contains("R"))
                    {
                        programOut[lineIndex].ifIns.condition[0].i_addType = INDIRECT;
                        programOut[lineIndex].ifIns.condition[0].pl_i = strToInt(str_i);
                    }
                    else
                    {
                        programOut[lineIndex].ifIns.condition[0].i_addType = DIRECT;
                        programOut[lineIndex].ifIns.condition[0].pl_i = strToInt(str_i);
                    }
                    if(str_j.contains("R"))
                    {
                        programOut[lineIndex].ifIns.condition[0].j_addType = INDIRECT;
                        programOut[lineIndex].ifIns.condition[0].pl_j = strToInt(str_j);
                    }
                    else
                    {
                        programOut[lineIndex].ifIns.condition[0].j_addType = DIRECT;
                        programOut[lineIndex].ifIns.condition[0].pl_j = strToInt(str_j);
                    }
                    if(str_k.contains("R"))
                    {
                        programOut[lineIndex].ifIns.condition[0].k_addType = INDIRECT;
                        programOut[lineIndex].ifIns.condition[0].pl_k = strToInt(str_k);
                    }
                    else
                    {
                        programOut[lineIndex].ifIns.condition[0].k_addType = DIRECT;
                        programOut[lineIndex].ifIns.condition[0].pl_k = strToInt(str_k);
                    }

                    programOut[lineIndex].ifIns.condition[0].pl_i = strToInt(plList[0]);
                    programOut[lineIndex].ifIns.condition[0].pl_j = strToInt(plList[1]);
                    programOut[lineIndex].ifIns.condition[0].pl_k = strToInt(plList[2]);

                    qDebug() << "==strToInt(plList[0])==="<<strToInt(plList[0])<<"===strToInt(plList[1])==="<<strToInt(plList[1])
                            <<"===strToInt(plList[2])==="<<strToInt(plList[2]);
                }
            }
            else
            {
                if("[]" == valType1)
                {
                    programOut[lineIndex].ifIns.condition[0].back_addType = DIRECT;
                    programOut[lineIndex].ifIns.condition[0].value_i = strToDouble(cap5Value);
                }
                else if("[R[]]" == valType1)
                {
                    programOut[lineIndex].ifIns.condition[0].back_addType = INDIRECT;
                    programOut[lineIndex].ifIns.condition[0].value_i = strToDouble(cap5Value);
                }
                else
                {
                    programOut[lineIndex].ifIns.condition[0].valueType = IF_CONST;
                    programOut[lineIndex].ifIns.condition[0].value_i = strToDouble(cap5Value);
                }
            }
         }

        //operatorType
        QString optype = rx2.cap(3);
        //            if(optype == ">")
        //            {
        //                programOut[lineNum].ifIns.condition[0].operatorType = GREATER;
        //            }
        //            else if(optype == ">=")
        //            {
        //                programOut[lineNum].ifIns.condition[0].operatorType = GREATER_EQU;
        //            }
        //            else if(optype == "=")
        //            {
        //                programOut[lineNum].ifIns.condition[0].operatorType = EQU;
        //            }
        //            else if(optype == "<=")
        //            {
        //                programOut[lineNum].ifIns.condition[0].operatorType = SMALLER_EQU;
        //            }
        //            else if(optype == "<")
        //            {
        //                programOut[lineNum].ifIns.condition[0].operatorType = SMALLER;
        //            }
        //            else if(optype == "<>")
        //            {
        //                programOut[lineNum].ifIns.condition[0].operatorType = NOT_EQU;
        //            }
        programOut[lineIndex].ifIns.condition[0].operatorType = patOperatorType(optype);
        //variable i
        int vari = strToInt(rx2.cap(2));
        programOut[lineIndex].ifIns.condition[0].variable_i = vari;
        //            //value i
        //            int vali = strToInt(rx2.cap(4));
        //            programOut[lineNum].ifIns.condition[0].value_i = vali;
    }
    else if(strListand.size() > 1 && strListor.size() == 1)
    {
        programOut[lineIndex].ifIns.andOrType = IF_AND;
        int and_n = strListand.size();
        //     qDebug()<<"programOut[lineNum].ifIns.condition***"<<and_n<<endl;
        programOut[lineIndex].ifIns.condition.resize(and_n);
        for(int x = 0;x < and_n;x++)
        {
            bool match = rx2.exactMatch(strListand[x]);
            if(match == false)
            {
                qDebug()<<"The"<<"line"<<lineIndex+1<<"wrong!";
                return 0;
            }
            strListand[x].indexOf(rx2);
            //variableType
            QString vartype = strFilt(rx2.cap(1));
            if(vartype == "R")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_R;
            }
            else if(vartype == "AO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_AO;
            }
            else if(vartype == "AI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_AI;
            }
            else if(vartype == "GO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_GO;
            }
            else if(vartype == "GI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_GI;
            }
            else if(vartype == "DO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_DO;
            }
            else if(vartype == "DI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_DI;
            }
            else if(vartype == "RO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_RO;
            }
            else if(vartype == "RI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_RI;
            }
            else if(vartype == "SO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_SO;
            }
            else if(vartype == "SI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_SI;
            }
            else if(vartype == "UO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_UO;
            }
            else if(vartype == "UI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_UI;
            }
            else if(vartype == "PL")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_PL;
            }
            QString varType2 = strFilt(rx2.cap(2));
            if("R[]" == varType2)
            {
                programOut[lineIndex].ifIns.condition[x].front_addType = INDIRECT;
            }
            else
            {
                programOut[lineIndex].ifIns.condition[x].front_addType = DIRECT;
            }
            //valuetype
            QString valtype = strFilt(rx2.cap(4));
            if(valtype == "R")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_R;
            }
            else if(valtype == "ON")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_ON;
            }
            else if(valtype == "OFF")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_OFF;
            }
            else if(valtype == "DO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_DO;
            }
            else if(valtype == "DI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_DI;
            }
            else if(valtype == "RO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_RO;
            }
            else if(valtype == "RI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_RI;
            }
            else if(valtype == "SO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_SO;
            }
            else if(valtype == "SI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_SI;
            }
            else if(valtype == "UO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_UO;
            }
            else if(valtype == "UI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_UI;
            }
            else if(valtype == "PL")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_PL;
            }
            else
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_CONST;
                programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(rx2.cap(4));
            }

            QString cap5Value = rx2.cap(5);
            QString valType1 = strFilt(cap5Value);
            if(!cap5Value.isEmpty())
            {
                if(cap5Value.contains(","))
                {
                    if(2 == cap5Value.count(","))
                    {
                        cap5Value = cap5Value.remove(" ");
                        cap5Value = cap5Value.remove("[");
                        cap5Value = cap5Value.remove("]");
                        QStringList plList = cap5Value.split(",");

                        programOut[lineIndex].ifIns.condition[x].valueType = IF_PL_IJK;
                        for(int j = 0; j < plList.size();j++)
                        {
                            if("*" == plList[j])
                            {
                                plList[j] = "100000";
                            }
                            else if("2-0" == plList[j])
                            {
                                plList[j] = "1000";
                            }
                            else if("2-1" == plList[j])
                            {
                                plList[j] = "1001";
                            }
                        }

                        QString str_i,str_j,str_k;

                        str_i = plList[0];
                        str_j = plList[1];
                        str_k = plList[2];

                        if(str_i.contains("R"))
                        {
                            programOut[lineIndex].ifIns.condition[x].i_addType = INDIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_i = strToInt(str_i);
                        }
                        else
                        {
                            programOut[lineIndex].ifIns.condition[x].i_addType = DIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_i = strToInt(str_i);
                        }
                        if(str_j.contains("R"))
                        {
                            programOut[lineIndex].ifIns.condition[x].j_addType = INDIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_j = strToInt(str_j);
                        }
                        else
                        {
                            programOut[lineIndex].ifIns.condition[x].j_addType = DIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_j = strToInt(str_j);
                        }
                        if(str_k.contains("R"))
                        {
                            programOut[lineIndex].ifIns.condition[x].k_addType = INDIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_k = strToInt(str_k);
                        }
                        else
                        {
                            programOut[lineIndex].ifIns.condition[x].k_addType = DIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_k = strToInt(str_k);
                        }

                        programOut[lineIndex].ifIns.condition[x].pl_i = strToInt(plList[0]);
                        programOut[lineIndex].ifIns.condition[x].pl_j = strToInt(plList[1]);
                        programOut[lineIndex].ifIns.condition[x].pl_k = strToInt(plList[2]);

                        qDebug() << "==strToInt(plList[0])==="<<strToInt(plList[0])<<"===strToInt(plList[1])==="<<strToInt(plList[1])
                                <<"===strToInt(plList[2])==="<<strToInt(plList[2]);
                    }
                }
                else
                {
                    if("[]" == valType1)
                    {
                        programOut[lineIndex].ifIns.condition[x].back_addType = DIRECT;
                        programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(cap5Value);
                    }
                    else if("[R[]]" == valType1)
                    {
                        programOut[lineIndex].ifIns.condition[x].back_addType = INDIRECT;
                        programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(cap5Value);
                    }
                    else
                    {
                        programOut[lineIndex].ifIns.condition[x].valueType = IF_CONST;
                        programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(cap5Value);
                    }
                }
            }
            //operatorType
            QString optype = rx2.cap(3);
            //                if(optype == ">")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = GREATER;
            //                }
            //                else if(optype == ">=")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = GREATER_EQU;
            //                }
            //                else if(optype == "=")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = EQU;
            //                }
            //                else if(optype == "<=")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = SMALLER_EQU;
            //                }
            //                else if(optype == "<")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = SMALLER;
            //                }
            //                else if(optype == "<>")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = NOT_EQU;
            //                }
            programOut[lineIndex].ifIns.condition[x].operatorType = patOperatorType(optype);
            //variable i
            int vari = strToInt(rx2.cap(2));
            programOut[lineIndex].ifIns.condition[x].variable_i = vari;
            //                //value i
            //                int vali = strToInt(rx2.cap(4));
            //                programOut[lineNum].ifIns.condition[x].value_i = vali;
        }
    }
    else if(strListand.size() == 1 && strListor.size() > 1)
    {
        programOut[lineIndex].ifIns.andOrType = IF_OR;
        int or_n = strListor.size();
        programOut[lineIndex].ifIns.condition.resize(or_n);
        for(int x = 0;x < or_n;x++)
        {
            bool match = rx2.exactMatch(strListor[x]);
            if(match == false)
            {
                qDebug()<<"The"<<"line"<<lineIndex+1<<"wrong!";
                return 0;
            }
            strListor[x].indexOf(rx2);
            //variableType
            QString vartype = strFilt(rx2.cap(1));
            //enum IF_COND_TYPE {IF_R,IF_AO,IF_AI,IF_GO,IF_GI,IF_DO,IF_DI,IF_RO,IF_RI,IF_SO,IF_SI,IF_UO,IF_UI,IF_ON,IF_OFF};
            if(vartype == "R")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_R;
            }
            else if(vartype == "AO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_AO;
            }
            else if(vartype == "AI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_AI;
            }
            else if(vartype == "GO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_GO;
            }
            else if(vartype == "GI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_GI;
            }
            else if(vartype == "DO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_DO;
            }
            else if(vartype == "DI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_DI;
            }
            else if(vartype == "RO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_RO;
            }
            else if(vartype == "RI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_RI;
            }
            else if(vartype == "SO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_SO;
            }
            else if(vartype == "SI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_SI;
            }
            else if(vartype == "UO")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_UO;
            }
            else if(vartype == "UI")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_UI;
            }
            else if(vartype == "PL")
            {
                programOut[lineIndex].ifIns.condition[x].variableType = IF_PL;
            }
            QString varType2 = strFilt(rx2.cap(2));
            if("R[]" == varType2)
            {
                programOut[lineIndex].ifIns.condition[x].front_addType = INDIRECT;
            }
            else
            {
                programOut[lineIndex].ifIns.condition[x].front_addType = DIRECT;
            }

            //valuetype
            QString valtype = strFilt(rx2.cap(4));
            if(valtype == "R")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_R;
            }
            else if(valtype == "ON")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_ON;
            }
            else if(valtype == "OFF")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_OFF;
            }
            else if(valtype == "DO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_DO;
            }
            else if(valtype == "DI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_DI;
            }
            else if(valtype == "RO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_RO;
            }
            else if(valtype == "RI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_RI;
            }
            else if(valtype == "SO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_SO;
            }
            else if(valtype == "SI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_SI;
            }
            else if(valtype == "UO")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_UO;
            }
            else if(valtype == "UI")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_UI;
            }
            else if(valtype == "PL")
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_PL;
            }
            else
            {
                programOut[lineIndex].ifIns.condition[x].valueType = IF_CONST;
                programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(rx2.cap(4));
            }

            QString cap5Value = rx2.cap(5);
            QString valType1 = strFilt(cap5Value);
            if(!cap5Value.isEmpty())
            {
                if(cap5Value.contains(","))
                {
                    if(2 == cap5Value.count(","))
                    {
                        cap5Value = cap5Value.remove(" ");
                        cap5Value = cap5Value.remove("[");
                        cap5Value = cap5Value.remove("]");
                        QStringList plList = cap5Value.split(",");

                        programOut[lineIndex].ifIns.condition[x].valueType = IF_PL_IJK;
                        for(int j = 0; j < plList.size();j++)
                        {
                            if("*" == plList[j])
                            {
                                plList[j] = "100000";
                            }
                            else if("2-0" == plList[j])
                            {
                                plList[j] = "1000";
                            }
                            else if("2-1" == plList[j])
                            {
                                plList[j] = "1001";
                            }
                        }

                        QString str_i,str_j,str_k;

                        str_i = plList[0];
                        str_j = plList[1];
                        str_k = plList[2];

                        if(str_i.contains("R"))
                        {
                            programOut[lineIndex].ifIns.condition[x].i_addType = INDIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_i = strToInt(str_i);
                        }
                        else
                        {
                            programOut[lineIndex].ifIns.condition[x].i_addType = DIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_i = strToInt(str_i);
                        }
                        if(str_j.contains("R"))
                        {
                            programOut[lineIndex].ifIns.condition[x].j_addType = INDIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_j = strToInt(str_j);
                        }
                        else
                        {
                            programOut[lineIndex].ifIns.condition[x].j_addType = DIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_j = strToInt(str_j);
                        }
                        if(str_k.contains("R"))
                        {
                            programOut[lineIndex].ifIns.condition[x].k_addType = INDIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_k = strToInt(str_k);
                        }
                        else
                        {
                            programOut[lineIndex].ifIns.condition[x].k_addType = DIRECT;
                            programOut[lineIndex].ifIns.condition[x].pl_k = strToInt(str_k);
                        }

                        programOut[lineIndex].ifIns.condition[x].pl_i = strToInt(plList[0]);
                        programOut[lineIndex].ifIns.condition[x].pl_j = strToInt(plList[1]);
                        programOut[lineIndex].ifIns.condition[x].pl_k = strToInt(plList[2]);

                        qDebug() << "==strToInt(plList[0])==="<<strToInt(plList[0])<<"===strToInt(plList[1])==="<<strToInt(plList[1])
                                <<"===strToInt(plList[2])==="<<strToInt(plList[2]);
                    }
                }
                else
                {
                    if("[]" == valType1)
                    {
                        programOut[lineIndex].ifIns.condition[x].back_addType = DIRECT;
                        programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(cap5Value);
                    }
                    else if("[R[]]" == valType1)
                    {
                        programOut[lineIndex].ifIns.condition[x].back_addType = INDIRECT;
                        programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(cap5Value);
                    }
                    else
                    {
                        programOut[lineIndex].ifIns.condition[x].valueType = IF_CONST;
                        programOut[lineIndex].ifIns.condition[x].value_i = strToDouble(cap5Value);
                    }
                }
            }
            //operatorType
            QString optype = rx2.cap(3);
            //                if(optype == ">")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = GREATER;
            //                }
            //                else if(optype == ">=")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = GREATER_EQU;
            //                }
            //                else if(optype == "=")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = EQU;
            //                }
            //                else if(optype == "<=")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = SMALLER_EQU;
            //                }
            //                else if(optype == "<")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = SMALLER;
            //                }
            //                else if(optype == "<>")
            //                {
            //                    programOut[lineNum].ifIns.condition[x].operatorType = NOT_EQU;
            //                }

            programOut[lineIndex].ifIns.condition[x].operatorType = patOperatorType(optype);
            //variable i
            int vari = strToInt(rx2.cap(2));

            programOut[lineIndex].ifIns.condition[x].variable_i = vari;
            //                //value i
            //                int vali = strToInt(rx2.cap(4));
            //                programOut[lineNum].ifIns.condition[x].value_i = vali;
        }
    }
    /********************************************************/
    return 1;
}


/***************SELECT指令处理函数********************/
int ProgramRegExp::patSelect(QString programStr, int lineIndex, Program &programOut)
{
    programOut[lineIndex].type = SELECT;
    QString pattern1("\\s*([SELECT]{6})\\s*([R]\\[\\d+\\])\\s*=\\s*([R]?\\[?\\d+\\]?)\\s*,\\s*(.*)");
    QString pattern2("\\s*([ELSE=]{1,4})\\s*([R]?\\[?\\d*\\]?)\\s*,\\s*(.*)");
    QRegExp rx1(pattern1);
    QRegExp rx2(pattern2);
    bool match;
    //pattern1
    if((match = rx1.exactMatch(programStr)) == true)
    {
        programStr.indexOf(rx1);
        int regi = strToInt(rx1.cap(2));
        programOut[lineIndex].select.regNumber=regi;
        QString r=strFilt(rx1.cap(3));
        if(r == "R[]")
        {
            programOut[lineIndex].select.valueType = SEL_R;
            int v = strToInt(rx1.cap(3));
            programOut[lineIndex].select.value = v;
        }
        else
        {
            programOut[lineIndex].select.valueType = CONSTANT;
            int val = strToInt(rx1.cap(3));
            programOut[lineIndex].select.value = val;
        }
        int protype = patExtractInstructionType(rx1.cap(4));
        if(protype == CALL)
        {
            programOut[lineIndex].select.jmpCallType = SEL_CALL;
            patCall(rx1.cap(4),programOut[lineIndex]);
            programOut[lineIndex].type = SELECT;
            programOut[lineIndex].select.callProcess = programOut[lineIndex].call;
        }
        else if(protype == JUMP)
        {
            programOut[lineIndex].select.jmpCallType = SEL_JMP;
            patJump(rx1.cap(4),programOut[lineIndex]);
            programOut[lineIndex].type = SELECT;
            programOut[lineIndex].select.jumpProcess = programOut[lineIndex].jump;
        }
        programOut[lineIndex].select.elseFlag = false;
    }
    //pattern2
    else if((match = rx2.exactMatch(programStr)) == true)
    {
        programStr.indexOf(rx2);
        //regNuber
        if(SELECT == programOut[lineIndex-1].type)
        {
            programOut[lineIndex].select.regNumber = programOut[lineIndex-1].select.regNumber;
        }
        else
        {
            //errCmdFlag = EM_CF_ON;
            qDebug()<<"MessageLog::getInstance()->addMessage";
            //MessageLog::getInstance()->addMessage( ENUM_MSG_REMIND, "ProgramEngine", "ProgramEngine",  3020, robotId , 0, 0);
        }
        //jmpCallType callProcess jumpProcess
        int protype2 = patExtractInstructionType(rx2.cap(3));
        if(protype2 == CALL)
        {
            programOut[lineIndex].select.jmpCallType = SEL_CALL;
            patCall(rx2.cap(3),programOut[lineIndex]);
            programOut[lineIndex].type = SELECT;
            programOut[lineIndex].select.callProcess = programOut[lineIndex].call;
        }
        else if(protype2 == JUMP)
        {
            programOut[lineIndex].select.jmpCallType = SEL_JMP;
            patJump(rx2.cap(3),programOut[lineIndex]);
            programOut[lineIndex].type = SELECT;
            programOut[lineIndex].select.jumpProcess = programOut[lineIndex].jump;
        }
        //valueType value elseflag
        if(rx2.cap(1) == "=")
        {
            QString r2=strFilt(rx2.cap(2));
            if(r2 == "R[]")
            {
                programOut[lineIndex].select.valueType = SEL_R;
                int v2 = strToInt(rx2.cap(2));
                programOut[lineIndex].select.value = v2;
            }
            else
            {
                programOut[lineIndex].select.valueType = CONSTANT;
                int val2 = strToInt(rx2.cap(2));
                programOut[lineIndex].select.value = val2;
            }
            programOut[lineIndex].select.elseFlag = false;
        }
        else if(rx2.cap(1) == "ELSE")
        {
            programOut[lineIndex].select.elseFlag = true;
        }
    }
    return 1;
}

/***************RUN指令处理函数****************＊****/
int ProgramRegExp::patRun(QString programStr,Line &lineOut)
{
    lineOut.type = RUN;

    //    qDebug()<<"&&&&&&&&&&&&&"<<__FUNCTION__<<"-----------"<<__LINE__<<"i ="<<i<<"j ="<<j<<"str =***"<<str<<endl;
// QString pattern("\\s*([CALL]{4})\\s*(\\S*)\\s*(.*)");
    QString pattern("\\s*([RUN]{3})\\s*(\\S*)\\s*;(.*)");
    QRegExp rx(pattern);
    programStr.indexOf(rx);

    QString name = rx.cap(2);
    lineOut.runInstruct.programName = name;
    return 1;
}

/***************FOR指令处理函数****************＊*****/
int ProgramRegExp::patFor(QString programStr,Line &lineOut)
{

    QString pattern1("\\s*([FOR]{3})\\s*([R]\\[\\d+\\])\\s*=\\s*([AR]{0,2}\\[?\\d+\\]?)\\s*([TODOWN]{2,6})\\s*([AR]{0,2}\\[?\\d+\\]?)\\s*(.*)");
    QString pattern2("\\s*([ENDFOR]{6})\\s*(.*)");
    QRegExp rx1(pattern1);
    QRegExp rx2(pattern2);
    bool pat1 = rx1.exactMatch(programStr);
    bool pat2 = rx2.exactMatch(programStr);
//    qDebug() << "**pat1***"<<pat1<<"**pat2***"<<pat2<<endl;
    if(pat1 == true && pat2 == false)
    {
        lineOut.type = FOR;
        programStr.indexOf(rx1);
        //initial the first flag
        lineOut.forInstruct.firstFlag = true;
        lineOut.forInstruct.forCompleteFlag = false;
        int reg_i = strToInt(rx1.cap(2));
        lineOut.forInstruct.registerNum = reg_i;
        QString init_type = strFilt(rx1.cap(3));
        if(init_type == "R[]")
        {
            lineOut.forInstruct.initialType = FOR_R;
        }
        else if(init_type == "AR[]")
        {
            lineOut.forInstruct.initialType = FOR_AR;
        }
        else
        {
            lineOut.forInstruct.initialType = INITIAL_CONST;
        }
        int init_val = strToInt(rx1.cap(3));
        lineOut.forInstruct.initialValue = init_val;
        QString tar_type = strFilt(rx1.cap(5));
        if(tar_type == "R[]")
        {
            lineOut.forInstruct.targetType = TARGET_R;
        }
        else if(tar_type == "AR[]")
        {
            lineOut.forInstruct.targetType = TARGET_AR;
        }
        else
        {
            lineOut.forInstruct.targetType = TARGET_CONST;
        }
        int tar_val = strToInt(rx1.cap(5));
        lineOut.forInstruct.targetValue = tar_val;
        if(rx1.cap(4) == "TO")
        {
            lineOut.forInstruct.actionType = TO;
            lineOut.forInstruct.forFlag = true;
        }
        else if(rx1.cap(4) == "DOWNTO")
        {
            lineOut.forInstruct.actionType = DOWNTO;
            lineOut.forInstruct.forFlag = false;
        }
    }
    else if(pat1 == false && pat2 == true)
    {
        lineOut.type = ENDFOR;
    }
    return 1;
}

/**************REGISTER指令处理函数****************＊*****/
int ProgramRegExp::patRegister(QString programStr,Line &lineOut)
{
    //  qDebug()<<"patRegister*****************\n\n\n\n\n\n\n\n\n\n*****************\n\n\n\n******************"<<endl;
    int ownerStart = programStr.indexOf("//");
    programStr = programStr.left(ownerStart);
    lineOut.type = REG;
    QString pattern1 = ("([PSRL]{1,2})\\[([R]?\\[?\\d+\\]?)\\s*,?\\s*(\\d*)\\s*:?\\s*(\\w*)\\]\\s*=(.*)");
    QRegExp rx1(pattern1);
    programStr.indexOf(rx1);
    /*********存储等号左边的内容**********/
    if(rx1.cap(1) == "R")
    {
        lineOut.reg.type = REG_INS;
    }
    else if(rx1.cap(1) == "PR")
    {
        if(rx1.cap(3) == "")
        {
            lineOut.reg.type = POS_REG_INS;
        }
        else
        {
            lineOut.reg.type = POS_REG_AXIS_INS;
        }
    }
    else if(rx1.cap(1) == "PL")
    {
        lineOut.reg.type = AR_PAL_REG_INS;
    }
    else if(rx1.cap(1) == "SR")
    {
        lineOut.reg.type = STR_REG;
    }
    int ri = strToInt(rx1.cap(2));
    int rj = strToInt(rx1.cap(3));
    lineOut.reg.i = ri;
    lineOut.reg.j = rj;
    lineOut.reg.comment = rx1.cap(4);
    if(strFilt(rx1.cap(2)) == "R[]")
    {
        lineOut.reg.addressType = INDIRECT;
    }
    else
    {
        lineOut.reg.addressType = DIRECT;
    }
    /*********存储等号后边的内容***********/
    /****先取出等号后边的内容,再放在QMap中****/
    QMap<int, QString> map;
    QString strpro = rx1.cap(5);
    strpro.replace(QString(" "),QString(""));//  去掉空格
    strpro.replace(";","");
    QString  strchar ;
    QStringList  strList;
    int xi = 0;
    int p1;
    int p2;

    /**********************获取【i、j、k】*******专用于PL指令**************************/
    QMap <int,int> plMap;
    plMap.clear();

    QVector <int> leftList;
    QVector <int> rightList;
    leftList.clear();
    rightList.clear();

    int plCount = 0;
    int pcCount = 0;
    /*********获取【i，j，k】**********/
    for(int i = 0; i < strpro.length();i++)
    {
        if('[' == strpro[i])
        {
            leftList.append(i);
        }
        else if(']' == strpro[i])
        {
            rightList.append(i);
        }
    }

//    qDebug() << __LINE__<<"==strpro=="<<strpro<<"===leftList=="<<leftList<<"=rightList=="<<rightList;

    /***************获取相匹配的括号的位置*****************/
    QString plTempStr;
    if(leftList.size() > 0)
    {
        for(int i = leftList[pcCount]; i < strpro.length();i++)
        {
            if('[' == strpro[i])
            {
                plCount++;
            }
            else if(']' == strpro[i])
            {
                plCount--;
            }

            if(0 == plCount)
            {
                plTempStr = strpro.mid(leftList[pcCount],i - leftList[pcCount]+ 1);
                if(plTempStr.count(",") > 1)
                {
                    plMap.insert(leftList[pcCount],i);
                }
                if(pcCount < leftList.size() - 1)
                {
                    i = leftList[++pcCount] - 1;
                }
            }
        }

//        qDebug() << __LINE__<<"***STRPRO***"<<strpro<<endl;
        QString tempStr;
        int front_i,back_i;
        for(int i = 0; i < plMap.size();i++)
        {
            front_i = plMap.keys().at(i);
            back_i = plMap.values().at(i);
            tempStr = strpro.mid(front_i,back_i - front_i + 1);
//            qDebug() << __LINE__<<"****i**"<<i<<"**front_i***"<<front_i<<"***back_i***"<<back_i<<"***tempStr**"<<tempStr<<endl;
            int count = tempStr.count(",");
            if(2 == count)
            {
//                qDebug() << "****i**"<<i<<"**front_i***"<<front_i<<"***back_i***"<<back_i<<"***tempStr**"<<tempStr<<endl;
                QString strget = tempStr;
                map.insert(front_i,strget);

                QString str;
                str.fill('$',back_i - front_i + 1);
                strpro.replace(front_i,back_i - front_i + 1,str);
            }
        }
    }

    /*************获取TIMER[] , UFRAM[], UTOOL[]*********/
    strchar  = "TIMER;UFRAM;UTOOL";
    strList = strchar.split(";");
    xi = 0;
    while(xi < strList.length())
    {
        p1 = strpro.indexOf(strList[xi]);
        if(p1 != -1)
        {
            p2 = p1;
            while(1)
            {
                if(strpro.mid(p2,1) == "]")
                    break;
                p2++;
            }
            QString strget = strpro.mid(p1,p2-p1+1);
            map.insert(p1,strget);      //插入到QMAP中
            strpro.replace(p1,5,"@@@@@");
        }
        else if(p1 == -1)
        {
            xi++;
        }
    }
    /******************获取TIMER_OVER[],************************/

    strchar = "TIMER_OVERFLOW:ABCDE_FGHIJKLM";
    strList = strchar.split(":");
    xi = 0;
    /*********TIMER_OVERFLOW[i]***********/
    p1 = strpro.indexOf(strchar);

    while(xi < strList.length())
    {
        p1 = strpro.indexOf(strList[xi]);
        if(p1 != -1)
        {
            p2 = p1;
            while(1)
            {
                if(strpro.mid(p2,1) == "]")
                    break;
                p2++;
            }
            QString strget = strpro.mid(p1,p2-p1+1);
//            qDebug() << "==strget==="<<strget<<endl;
            map.insert(p1,strget);      //插入到QMAP中
            strpro.replace(p1,14,"@@@@@@@@@@@@@@");
        }
        else if(-1 == p1)
        {
            xi++;
        }
    }
//    qDebug() << "****strpro*****"<<strpro<<endl;

//    qDebug() << __FUNCTION__ << "******"<<__LINE__<<endl;
    /************获取 DIV MOD******************/
    strchar  = "MOD;DIV";
    strList = strchar.split(";");
    xi = 0;
    while(xi < strList.length())
    {
        p1 = strpro.indexOf(strList[xi]);
        if(p1 != -1)
        {
            QString strget = strpro.mid(p1,3);
            map.insert(p1,strget);      //插入到QMAP中
            strpro.replace(p1,3,"###");
        }
        else if(p1 == -1)
        {
            xi++;
        }
    }
    /*******PR GI GO AI AO DI DO RI RO SI SO UI UO SR AR PL R[ P[,要放在获取完TIMER[] 和DIV之后*********/
    strchar  = "PR:GI:GO:AI:AO:DI:DO:RI:RO:SI:SO:UI:UO:SR:AR:PL:R[:P[";
    strList = strchar.split(":");
    xi = 0;
    while(xi < strList.length())
    {
        p1 = strpro.indexOf(strList[xi]);
        if(p1 != -1)
        {
            p2 = p1;
            while(1)
            {
                if(strpro.mid(p2,1) == "]")
                    break;
                p2++;
            }
            QString strget = strpro.mid(p1,p2-p1+1);
//            qDebug() << "==strget==="<<strget<<endl;
            map.insert(p1,strget);      //插入到QMAP中

            strpro.replace(p1,2,"@@");
            strget.replace(0,2,"@@");   //因为PR[R[]]里面有两个R；
            int R = strget.indexOf("R");     //判断字符串里面是否有R[]，如果有应该替换掉，避免误认为是外面的R[];
            if(R != -1)
            {
                strpro.replace(p1+R,1,"@");
            }
        }
        else if(p1 == -1)
        {
            xi++;
        }
    }
    /*********************获取“+-* / ( )****************/
    strchar = "+ - * / ( )";
    strList = strchar.split(" ");
    xi  = 0;
    int op = 0;
    while(xi < strList.length() )
    {
        op = strpro.indexOf(strList[xi]);
        if(op != -1)
        {
            QString oper = strpro.mid(op,1);
            map.insert( op,oper);     //插入到QMAP
            strpro.replace(op,1,"#");
        }
        else if(op == -1)
        {
            xi++;
        }
    }
    /***********获取 Lpos Jpos ,要 放在获取完＋－＊／（）之后**************/
    strchar  = "Lpos;Jpos";
    strList = strchar.split(";");
    xi = 0;
    while(xi < strList.length())
    {
        p1 = strpro.indexOf(strList[xi]);
        if(p1 != -1)
        {
            QString strget = strpro.mid(p1,4);
            map.insert(p1,strget);      //插入到QMAP中
            strpro.replace(p1,4,"@@@@");
        }
        else if(p1 == -1)
        {
            xi++;
        }
    }

    /**************获取常数项***************/
    while(1)
    {
        p1 = strpro.indexOf("#");
        if(p1 == -1)
        {
            break;
        }
        if(strpro.mid(p1+1,1)>="0" && strpro.mid(p1+1,1)<="9")
        {
            p2 = p1;
            while(1)
            {
                p2++;
                if(strpro.mid(p2,1) == "#" || strpro.mid(p2,1) == "")
                {
                    break;
                }
            }
            QString strget = strpro.mid(p1+1,p2-p1-1);
            map.insert(p1+1,strget);      //插入到QMAP中
        }
        strpro.replace(p1,1,"$");
    }
    //第一个字符串为常数项的情况
//    qDebug() << "***strpro****"<<strpro<<endl;
    //        if(!strpro.contains("$"))//全是数字，没有字母
    //        {
    //            QString strget = strpro;
    //            map.insert(0,strget);
    //        }
    //        else
    {
        if(strpro.mid(0,1) >= "0" && strpro.mid(0,1)<="9")
        {
            p1 = 0;
            while(1)
            {
                p1++;
//                qDebug()<< "---mid---"<<strpro.mid(p1,1)<<endl;
                if(strpro.mid(p1,1) == "$")
                {
                    break;
                }
                else if(strpro.mid(p1,1) == "")
                {
                    break;
                }
            }
            QString strget = strpro.mid(0,p1);
            map.insert(0,strget);      //插入到QMAP中
        }
    }
    /********************将获得的每个字符串按顺序存储**********************/
    int pi ;
    int pj ;
    int sum = 0;
    float val;
    QString plStr;
    QString strfile;
    QMap<int, QString>::const_iterator mi;
    for( mi=map.constBegin(); mi!=map.constEnd(); ++mi)
    {
        sum++;
        lineOut.reg.regcondition.resize(sum);
        if(lineOut.reg.type == AR_PAL_REG_INS)
        {
            strList = mi.value().split("[");
            if("PL" == strList[0])
            {
                lineOut.reg.regcondition[sum - 1].valueType = REG_PL;
                if(strList.size()>1)
                {
                    if(strList[1] == "R")
                    {
                        lineOut.reg.regcondition[sum-1].rightVarType = INDIRECT;
//                        qDebug() << "**strList[1]***"<<strList[2]<<endl;
                        lineOut.reg.regcondition[sum - 1].plVal = strToInt(strList[2]);
                    }
                    else
                    {
                        lineOut.reg.regcondition[sum-1].rightVarType = DIRECT;
                        lineOut.reg.regcondition[sum-1].plVal = strToInt(strList[1]);
                    }
                }

            }
            else if("+" == strList[0])
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_ADD;
            }
            else if("-" == strList[0])
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_DEC;
            }
            else if(strList[0] == "(")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_LEFT_BRK;
            }
            else if(strList[0] == ")")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_RIGHT_BRK;
            }
            else
            {
                lineOut.reg.regcondition[sum - 1].valueType = REG_PL_CONST;
                plStr = mi.value();
                qDebug() << "**plStr**"<<plStr<<endl;
                if(2 == plStr.count(","))
                {
                    plStr = plStr.remove(" ");
                    plStr = plStr.remove("[");
                    plStr = plStr.remove("]");
                    strList = plStr.split(",");
                    for(int j = 0; j < strList.size();j++)
                    {
                        if("*" == strList[j])
                        {
                            strList[j] = "100000";
                        }
                        else if("2-0" == strList[j])
                        {
                            strList[j] = "1000";
                        }
                        else if("2-1" == strList[j])
                        {
                            strList[j] = "1001";
                        }
                        QString str_i,str_j,str_k;

                        str_i = strList[0];
                        str_j = strList[1];
                        str_k = strList[2];

                        if(str_i.contains("R"))
                        {
                            lineOut.reg.regcondition[sum - 1].pl_iVarType = INDIRECT;
                            lineOut.reg.regcondition[sum - 1].i = strToInt(str_i);
                        }
                        else
                        {
                            lineOut.reg.regcondition[sum - 1].pl_iVarType = DIRECT;
                            lineOut.reg.regcondition[sum - 1].i = strToInt(str_i);
                        }
                        if(str_j.contains("R"))
                        {
                            lineOut.reg.regcondition[sum - 1].pl_jVarType = INDIRECT;
                            lineOut.reg.regcondition[sum - 1].j = strToInt(str_j);
                        }
                        else
                        {
                            lineOut.reg.regcondition[sum - 1].pl_jVarType = DIRECT;
                            lineOut.reg.regcondition[sum - 1].j = strToInt(str_j);
                        }
                        if(str_k.contains("R"))
                        {
                            lineOut.reg.regcondition[sum - 1].pl_kVarType = INDIRECT;
                            lineOut.reg.regcondition[sum - 1].k = strToInt(str_k);
                        }
                        else
                        {
                            lineOut.reg.regcondition[sum - 1].pl_kVarType = DIRECT;
                            lineOut.reg.regcondition[sum - 1].k = strToInt(str_k);
                        }
                    }
                }
            }
        }
        else
        {
//            qDebug() << "***strList****"<<mi.value()<<endl;
            strList = mi.value().split("[") ;                          //如 ：R[R[2]] -> R   R 2]];
            if(strList[0] == "AR")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_AR;
            }
            else if(strList[0] == "R")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_R;
            }
            else if(strList[0] == "P")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_P;
            }
            else if(strList[0] == "PR")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_PR;
            }
            else if(strList[0] == "GI")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_GI;
            }
            else if(strList[0] == "GO")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_GO;
            }
            else if(strList[0] == "AI")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_AI;
            }
            else if(strList[0] == "AO")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_AO;
            }
            else if(strList[0] == "DI")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_DI;
            }
            else if(strList[0] == "DO")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_DO;
            }
            else if(strList[0] == "RI")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_RI;
            }
            else if(strList[0] == "RO")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_RO;
            }
            else if(strList[0] == "SI")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_SI;
            }
            else if(strList[0] == "SO")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_SO;
            }
            else if(strList[0] == "UI")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_UI;
            }
            else if(strList[0] == "UO")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_UO;
            }
            else if(strList[0] == "TIMER")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_TIMER;
            }
            else if(strList[0] == "TIMER_OVERFLOW")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_TIMER_OVERFLOW;
            }
            else if(strList[0] == "Lpos")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_Lpos;
            }
            else if(strList[0] == "Jpos")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_Jpos;
            }
            else if(strList[0] == "UFRAM")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_UFRAM;
            }
            else if(strList[0] == "UTOOL")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_UTOOL;
            }
            else if(strList[0] == "PL")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_PL;
            }
            else if(strList[0] == "MOD")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_MOD;
            }
            else if(strList[0] == "DIV")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_DIV;
            }
            else if(strList[0] == "+")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_ADD;
            }
            else if(strList[0] == "-")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_DEC;
            }
            else if(strList[0] == "*")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_MUL;
            }
            else if(strList[0] == "/")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_DIVIVIDE;
            }
            else if(strList[0] == "(")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_LEFT_BRK;
            }
            else if(strList[0] == ")")
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_RIGHT_BRK;
            }
            else
            {
                lineOut.reg.regcondition[sum-1].valueType = REG_CONST;
                val = strToDouble(strList[0]);
                lineOut.reg.regcondition[sum-1].val = val;
            }
            /*************判断地址类型************/
            if(strList.size()>1)
            {
                if(strList[1] == "R")
                {
                    lineOut.reg.regcondition[sum-1].rightVarType = INDIRECT;
                }
                else
                {
                    lineOut.reg.regcondition[sum-1].rightVarType = DIRECT;
                }
            }
            /***************存储 i,j***************/
            if( lineOut.reg.regcondition[sum-1].valueType != REG_CONST)
            {
                strList = mi.value().split(",") ;           //如 R[2,4] ->R[2  ;     4];
                pi = strToInt(strList[0]);
                lineOut.reg.regcondition[sum-1].i = pi;
                if(strList.size() > 1)
                {
                    pj = strToInt(strList[1]);
                    lineOut.reg.regcondition[sum-1].j = pj;
                    lineOut.reg.regcondition[sum-1].valueType = REG_PR_IJ;
                }
            }
        }
    }
    return 1;
}

int ProgramRegExp::patPal(QString programStr, Line &lineOut)
{
    lineOut.type = INS_PALLET;
    QString pattern1("\\s*([PALLETIZING]{11})\\s*-?\\s*([BENDx]{0,3})_?(\\d*)\\s*;\\s*//(.*)");
    QRegExp rx1(pattern1);


    if(rx1.exactMatch(programStr))
    {
        programStr.indexOf(rx1);

        QString name = rx1.cap(2);
        int num = rx1.cap(3).toInt();
        lineOut.palInstruct.stackNumber = num;
        if(name == "END")
        {
            lineOut.palInstruct.isStartSet = 0;

        }
        else
        {
            lineOut.palInstruct.isStartSet = 1;
        }
        lineOut.palInstruct.comment=rx1.cap(4);
        return 1;
    }
    else
    {

    }


    return 0;
}

int ProgramRegExp::patCoordinate(QString programStr, Line &lineOut)
{
    lineOut.type = COORDINATE;
    //UFRAME_NUM = 1;
//    QString pattern1("\\s*(UFRAME_NUM)\\s*\\=\\s*([0-9]|10)\\s*(.*)");
    QString pattern1("\\s*(UFRAME_NUM)\\s*\\=\\s*([R]?\\[?\\d+\\]?)\\s*(.*)");
    //UTOOL_NUM = 2;
//    QString pattern2("\\s*(UTOOL_NUM)\\s*\\=\\s*([0-9]|10)\\s*(.*)");
    QString pattern2("\\s*(UTOOL_NUM)\\s*\\=\\s*([R]?\\[?\\d+\\]?)\\s*(.*)");
    //UFRAME[3]=PR[5];
    QString pattern3("\\s*(UFRAME)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*=\\s*(PR)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*(.*)");
    //UTOOL[1]=PR[2];
    QString pattern4("\\s*(UTOOL)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*=\\s*(PR)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*(.*)");

    QRegExp rx1(pattern1);
    QRegExp rx2(pattern2);
    QRegExp rx3(pattern3);
    QRegExp rx4(pattern4);

    programStr.indexOf(rx1);
    programStr.indexOf(rx2);
    programStr.indexOf(rx3);
    programStr.indexOf(rx4);

    if(rx1.cap(1) == "UFRAME_NUM")
    {
        QString r = strFilt(rx1.cap(2));
        if("R[]" == r)
        {
            lineOut.coorInstruct.backType = INDIRECT;
        }
        else
        {
            lineOut.coorInstruct.backType = DIRECT;
        }
        int ufNum = strToInt(rx1.cap(2));

        lineOut.coorInstruct.coorType = UFRAME_TYPE;
        lineOut.coorInstruct.back_val = ufNum;
    }
    else if(rx2.cap(1) == "UTOOL_NUM")
    {
        QString r = strFilt(rx2.cap(2));
        if("R[]" == r)
        {
            lineOut.coorInstruct.backType = INDIRECT;
        }
        else
        {
            lineOut.coorInstruct.backType = DIRECT;
        }
        int utNum = strToInt(rx2.cap(2));
        lineOut.coorInstruct.coorType = UTOOL_TYPE;
        lineOut.coorInstruct.back_val = utNum;
    }
    else if("UFRAME" == rx3.cap(1))
    {
        int front_val = strToInt(rx3.cap(3));
        int back_val = strToInt(rx3.cap(7));

        lineOut.coorInstruct.coorType = UFRAME_PR_TYPE;
        lineOut.coorInstruct.front_val = front_val;
        lineOut.coorInstruct.back_val = back_val;
    }
    else if("UTOOL" == rx4.cap(1))
    {
        int front_val = strToInt(rx4.cap(3));
        int back_val = strToInt(rx4.cap(7));

        lineOut.coorInstruct.coorType = UTOOL_PR_TYPE;
        lineOut.coorInstruct.front_val = front_val;
        lineOut.coorInstruct.back_val = back_val;
    }

    return 1;
}

int ProgramRegExp::patWait(QString programStr, Line &lineOut)
{
    lineOut.type = WAIT;
    QString pattern13_1("\\s*(WAIT)\\s*(\\d+\\.?\\d*)\\s*sec\\s*(.*)");
    //     QString pattern13_2("\\s*(WAIT)\\s*([RAGDSUOI]{1,2})\\[([A]?[R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*([ODRSUNFI]{0,3}\\[?\\d*\\.?\\d*\\]?)\\s*,?\\s*(TIMEOUT)?\\s*,?\\s*(LBL)?(\\[\\d*\\])?\\s*(.*)");
//    QString pattern13_2("\\s*(WAIT)\\s*([RAGDSUOI]{1,2})\\[([A]?[R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*([ODRSUNFI/d]{1,})?\\[?([A]?[R]?\\[?\\d*\\.?\\d*\\])?\\]?\\s*,?\\s*(TIMEOUT)?\\s*,?\\s*(LBL)?(\\[\\d*\\])?\\s*([AR])?(\\[?[R]?\\[?\\d*\\.?\\d*\\]?\\]?)?\\s*(sec)?\\s*");
//    QString pattern13_2("\\s*(WAIT)\\s*([RAGDSUOI]{1,2})\\[([A]?[R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*([ODRSUNFI0123456789.]{1,})?\\[?([A]?[R]?\\[?\\d*\\.?\\d*\\])?\\]?\\s*,?\\s*(TIMEOUT)?\\s*,?\\s*(LBL)?(\\[\\d*\\])?\\s*([AR])?(\\[?[R]?\\[?\\d*\\.?\\d*\\]?\\]?)?\\s*(sec)?\\s*");
    QString pattern13_2("\\s*(WAIT)\\s*([RAGDSUOI]{1,2})\\[([A]?[R]?\\[?\\d+\\]?)\\]\\s*([>=<]{1,2})\\s*([ODRSUNFI0123456789.]{1,})?\\[?([A]?[R]?\\[?\\d*\\.?\\d*\\])?\\]?\\s*,?\\s*(TIMEOUT)?\\s*,?\\s*(LBL)?(\\[\\S*\\])?\\s*([AR])?(\\[?[R]?\\[?\\d*\\.?\\d*\\]?\\]?)?\\s*(sec)?\\s*");

    QString pattern13_3("\\s*(WAIT)\\s*([AR]{1,2})\\[([A]?[R]?\\[?\\d+\\]?)\\]\\s*");
    QString pattern13_4("\\s*(WAIT)\\s*");


    QRegExp rx13_1(pattern13_1 + srt_rx_notes);
    QRegExp rx13_2(pattern13_2 + srt_rx_notes);
    QRegExp rx13_3(pattern13_3 + srt_rx_notes);
    QRegExp rx13_4(pattern13_4 + srt_rx_notes);

    programStr.indexOf(rx13_1);
    programStr.indexOf(rx13_2);
    programStr.indexOf(rx13_3);
    programStr.indexOf(rx13_4);

    bool match;

//    qDebug() << "****1***"<<rx13_1.exactMatch(programStr)<<"==2===="<<rx13_2.exactMatch(programStr)<<"===3===="<<rx13_3.exactMatch(programStr)<<"\n\n";
    if((match = rx13_1.exactMatch(programStr)) == true)
    {
        lineOut.waitInstruct.type = WAIT_CONST_TIME;
        lineOut.waitInstruct.waitTime = strToDouble(rx13_1.cap(2));
    }
    else if((match = rx13_2.exactMatch(programStr)) == true)
    {
        QString front_varStr,front_varStr2,operStr,back_valStr,back_valStr2,proStr,proStr2,proStr3;
        QString front_str,back_str,back_str2;

        QString timeStr1,timeStr2,secStr;

        double val_i ;
        double front_i ;

        WAIT_INS_TYPE type;

        front_varStr = rx13_2.cap(2);
        front_varStr2 = rx13_2.cap(3);
        operStr = rx13_2.cap(4);
        back_valStr = rx13_2.cap(5);

        qDebug()<<"front_varStr"<<front_varStr<<",front_varStr2"<<front_varStr2<<",operStr"<<operStr
               <<",back_valStr"<<back_valStr;

        back_valStr2 = rx13_2.cap(6);
        proStr = rx13_2.cap(7);
        proStr2 = rx13_2.cap(8);

        QRegExp tmpRegExp("\\S*\\[(\\S*)\\]\\S*");
        rx13_2.cap(9).indexOf(tmpRegExp);
        proStr3 = tmpRegExp.cap(1);

        qDebug()<<"back_valStr2 "<<back_valStr2<<",proStr "<<proStr<<",proStr2 "<<proStr2
               <<",proStr3 "<<proStr3;

        timeStr1 = rx13_2.cap(10);
        timeStr2 = rx13_2.cap(11);
        secStr = rx13_2.cap(12);

        front_str = strFilt(front_varStr2);
        back_str = strFilt(back_valStr);
        back_str2 = strFilt(back_valStr2);

        front_i = strToDouble(front_varStr2);
//        val_i = strToInt(back_valStr2);
        val_i = strToDouble(back_valStr);

        if("R" == front_varStr)
        {
            if("R" == back_str)
            {
//                qDebug()<<"***R***R*"<<endl;
                type = WAIT_R_R ;
            }
            else
            {
//                qDebug() << "****R**CONST**"<<endl;
                type = WAIT_R_CONST ;
            }
        }
        else if("AO" == front_varStr)
        {
//            qDebug() << "****AO***"<<endl;
            if("R" == back_str)
            {
//                qDebug()<<"***AO***R*"<<endl;
                type = WAIT_AO_R ;
            }
            else
            {
//                qDebug() << "****AO**CONST**"<<endl;
                type = WAIT_AO_CONST ;
            }
        }
        else if("AI" == front_varStr)
        {
//            qDebug() << "****AI***"<<endl;
            if("R" == back_str)
            {
//                qDebug()<<"***AI***R*"<<endl;
                type = WAIT_AI_R ;
            }
            else
            {
//                qDebug() << "****AI**CONST**"<<endl;
                type = WAIT_AI_CONST ;
            }
        }
        else if("GO" == front_varStr)
        {
//            qDebug() << "****GO***"<<endl;
            if("R" == back_str)
            {
//                qDebug()<<"***GO***R*"<<endl;
                type = WAIT_GO_R ;
            }
            else
            {
//                qDebug() << "****GO**CONST**"<<endl;
                type = WAIT_GO_CONST ;
            }
        }
        else if("GI" == front_varStr)
        {
//            qDebug() << "****GI***"<<endl;
            if("R" == back_str)
            {
//                qDebug()<<"***GI***R*"<<endl;
                type = WAIT_GI_R ;
            }
            else
            {
//                qDebug() << "****GI**CONST**"<<endl;
                type = WAIT_GI_CONST ;
            }
        }
        else if("DO" == front_varStr)
        {
//            qDebug() << "****DO***"<<endl;
            if("ON" == back_str)
            {
//                qDebug()<<"***DO**ON***"<<endl;
                type = WAIT_DO_ON ;
            }
            else if("OFF" == back_str)
            {
//                qDebug()<<"***DO**OFF***"<<endl;
                type = WAIT_DO_OFF ;
            }
            else if("DO" == back_str)
            {
//                qDebug()<<"***DO**DO[]***"<<endl;
                type = WAIT_DO_DO ;
            }
            else if("DI" == back_str)
            {
//                qDebug()<<"***DO**DI[]***"<<endl;
                type = WAIT_DO_DI ;
            }
            else if("RO" == back_str)
            {
//                qDebug()<<"***DO**RO[]***"<<endl;
                type = WAIT_DO_RO ;
            }
            else if("RI" == back_str)
            {
//                qDebug()<<"***DO**RI[]***"<<endl;
                type = WAIT_DO_RI ;
            }
            else if("SO" == back_str)
            {
//                qDebug()<<"***DO**SO[]***"<<endl;
                type = WAIT_DO_SO ;
            }
            else if("SI" == back_str)
            {
//                qDebug()<<"***DO**SI[]***"<<endl;
                type = WAIT_DO_SI ;
            }
            else if("UO" == back_str)
            {
//                qDebug()<<"***DO**UO[]***"<<endl;
                type = WAIT_DO_UO ;
            }
            else if("UI" == back_str)
            {
//                qDebug()<<"***DO**UI[]***"<<endl;
                type = WAIT_DO_UI ;
            }
            else if("R" == back_str)
            {
//                qDebug()<<"***DO**R[]***"<<endl;
                type = WAIT_DO_R ;
            }
        }
        else if("DI" == front_varStr)
        {
//            qDebug() << "****DI***"<<endl;
            if("ON" == back_str)
            {
//                qDebug()<<"***DI**ON***"<<endl;
                type = WAIT_DI_ON ;
            }
            else if("OFF" == back_str)
            {
//                qDebug()<<"***DI**OFF***"<<endl;
                type = WAIT_DI_OFF ;
            }
            else if("DO" == back_str)
            {
//                qDebug()<<"***DI**DO[]***"<<endl;
                type = WAIT_DI_DO ;
            }
            else if("DI" == back_str)
            {
//                qDebug()<<"***DI**DI[]***"<<endl;
                type = WAIT_DI_DI ;
            }
            else if("RO" == back_str)
            {
//                qDebug()<<"***DI**RO[]***"<<endl;
                type = WAIT_DI_RO ;
            }
            else if("RI" == back_str)
            {
//                qDebug()<<"***DI**RI[]***"<<endl;
                type = WAIT_DI_RI ;
            }
            else if("SO" == back_str)
            {
//                qDebug()<<"***DI**SO[]***"<<endl;
                type = WAIT_DI_SO ;
            }
            else if("SI" == back_str)
            {
//                qDebug()<<"***DI**SI[]***"<<endl;
                type = WAIT_DI_SI ;
            }
            else if("UO" == back_str)
            {
//                qDebug()<<"***DI**UO[]***"<<endl;
                type = WAIT_DI_UO ;
            }
            else if("UI" == back_str)
            {
//                qDebug()<<"***DI**UI[]***"<<endl;
                type = WAIT_DI_UI ;
            }
            else if("R" == back_str)
            {
//                qDebug()<<"***DI**R[]***"<<endl;
                type = WAIT_DI_R ;
            }
        }
        else if("RO" == front_varStr)
        {
//            qDebug() << "****RO***"<<endl;
            if("ON" == back_str)
            {
//                qDebug()<<"**RO**ON***"<<endl;
                type = WAIT_RO_ON ;
            }
            else if("OFF" == back_str)
            {
//                qDebug()<<"***RO**OFF***"<<endl;
                type = WAIT_RO_OFF ;
            }
            else if("DO" == back_str)
            {
//                qDebug()<<"***RO**DO[]***"<<endl;
                type = WAIT_RO_DO;
            }
            else if("DI" == back_str)
            {
//                qDebug()<<"***RO**DI[]***"<<endl;
                type = WAIT_RO_DI ;
            }
            else if("RO" == back_str)
            {
//                qDebug()<<"***RO**RO[]***"<<endl;
                type = WAIT_RO_RO ;
            }
            else if("RI" == back_str)
            {
//                qDebug()<<"***RO**RI[]***"<<endl;
                type = WAIT_RO_RI ;
            }
            else if("SO" == back_str)
            {
//                qDebug()<<"***RO**SO[]***"<<endl;
                type = WAIT_RO_SO ;
            }
            else if("SI" == back_str)
            {
//                qDebug()<<"***RO**SI[]***"<<endl;
                type = WAIT_RO_SI ;
            }
            else if("UO" == back_str)
            {
//                qDebug()<<"***RO**UO[]***"<<endl;
                type = WAIT_RO_UO ;
            }
            else if("UI" == back_str)
            {
//                qDebug()<<"***RO**UI[]***"<<endl;
                type = WAIT_RO_UI ;
            }
            else if("R" == back_str)
            {
//                qDebug()<<"***RO**R[]***"<<endl;
                type = WAIT_RO_R ;
            }
        }
        else if("RI" == front_varStr)
        {
//            qDebug() << "****RI***"<<endl;
            if("ON" == back_str)
            {
//                qDebug()<<"***RI**ON***"<<endl;
                type = WAIT_RI_ON ;
            }
            else if("OFF" == back_str)
            {
//                qDebug()<<"***RI**OFF***"<<endl;
                type = WAIT_RI_OFF ;
            }
            else if("DO" == back_str)
            {
//                qDebug()<<"***RI**DO[]***"<<endl;
                type = WAIT_RI_DO ;
            }
            else if("DI" == back_str)
            {
//                qDebug()<<"***RI**DI[]***"<<endl;
                type = WAIT_RI_DI ;
            }
            else if("RO" == back_str)
            {
//                qDebug()<<"***RI**RO[]***"<<endl;
                type = WAIT_RI_RO ;
            }
            else if("RI" == back_str)
            {
//                qDebug()<<"***RI**RI[]***"<<endl;
                type = WAIT_RI_RI ;
            }
            else if("SO" == back_str)
            {
//                qDebug()<<"**RI**SO[]***"<<endl;
                type = WAIT_RI_SO ;
            }
            else if("SI" == back_str)
            {
//                qDebug()<<"***RI**SI[]***"<<endl;
                type = WAIT_RI_SI ;
            }
            else if("UO" == back_str)
            {
//                qDebug()<<"***RI**UO[]***"<<endl;
                type = WAIT_RI_UO ;
            }
            else if("UI" == back_str)
            {
//                qDebug()<<"***RI**UI[]***"<<endl;
                type = WAIT_RI_UI ;
            }
            else if("R" == back_str)
            {
//                qDebug()<<"***RI**R[]***"<<endl;
                type = WAIT_RI_R ;
            }
        }
        else if("SO" == front_varStr)
        {
//            qDebug() << "****SO***"<<endl;
            if("ON" == back_str)
            {
//                qDebug()<<"***SO**ON***"<<endl;
                type = WAIT_SO_ON ;
            }
            else if("OFF" == back_str)
            {
//                qDebug()<<"**SO**OFF***"<<endl;
                type = WAIT_SO_OFF ;
            }
            else if("DO" == back_str)
            {
//                qDebug()<<"***SO**DO[]***"<<endl;
                type = WAIT_SO_DO ;
            }
            else if("DI" == back_str)
            {
//                qDebug()<<"***SO**DI[]***"<<endl;
                type = WAIT_SO_DI ;
            }
            else if("RO" == back_str)
            {
                qDebug()<<"**SO**RO[]***"<<endl;
                type = WAIT_SO_RO ;
            }
            else if("RI" == back_str)
            {
                qDebug()<<"***SO**RI[]***"<<endl;
                type = WAIT_SO_RI ;
            }
            else if("SO" == back_str)
            {
                qDebug()<<"***SO**SO[]***"<<endl;
                type = WAIT_SO_SO ;
            }
            else if("SI" == back_str)
            {
                qDebug()<<"***SO**SI[]***"<<endl;
                type = WAIT_SO_SI ;
            }
            else if("UO" == back_str)
            {
                qDebug()<<"***SO**UO[]***"<<endl;
                type = WAIT_SO_UO ;
            }
            else if("UI" == back_str)
            {
                qDebug()<<"**SO**UI[]***"<<endl;
                type = WAIT_SO_UI ;
            }
            else if("R" == back_str)
            {
                qDebug()<<"***SO**R[]***"<<endl;
                type = WAIT_SO_R ;
            }
        }
        else if("SI" == front_varStr)
        {
            qDebug() << "****SI***"<<endl;
            if("ON" == back_str)
            {
                qDebug()<<"***SI**ON***"<<endl;
                type = WAIT_SI_ON ;
            }
            else if("OFF" == back_str)
            {
                qDebug()<<"**SI**OFF***"<<endl;
                type = WAIT_SI_OFF ;
            }
            else if("DO" == back_str)
            {
                qDebug()<<"***SI**DO[]***"<<endl;
                type = WAIT_SI_DO ;
            }
            else if("DI" == back_str)
            {
                qDebug()<<"***SI**DI[]***"<<endl;
                type = WAIT_SI_DI ;
            }
            else if("RO" == back_str)
            {
                qDebug()<<"***SI**RO[]***"<<endl;
                type = WAIT_SI_RO ;
            }
            else if("RI" == back_str)
            {
                qDebug()<<"**SI**RI[]***"<<endl;
                type = WAIT_SI_RI ;
            }
            else if("SO" == back_str)
            {
                qDebug()<<"***SI**SO[]***"<<endl;
                type = WAIT_SI_SO ;
            }
            else if("SI" == back_str)
            {
                qDebug()<<"***SI*SI[]***"<<endl;
                type = WAIT_SI_SI ;
            }
            else if("UO" == back_str)
            {
                qDebug()<<"**SI**UO[]***"<<endl;
                type = WAIT_SI_UO ;
            }
            else if("UI" == back_str)
            {
                qDebug()<<"**SI**UI[]***"<<endl;
                type = WAIT_SI_UI ;
            }
            else if("R" == back_str)
            {
                qDebug()<<"***SI**R[]***"<<endl;
                type = WAIT_SI_R ;
            }
        }
        else if("UO" == front_varStr)
        {
            qDebug() << "****UO***"<<endl;
            if("ON" == back_str)
            {
                qDebug()<<"**UO**ON***"<<endl;
                type = WAIT_UO_ON ;
            }
            else if("OFF" == back_str)
            {
                qDebug()<<"***UO**OFF***"<<endl;
                type = WAIT_UO_OFF ;
            }
            else if("DO" == back_str)
            {
                qDebug()<<"***UO**DO[]***"<<endl;
                type = WAIT_UO_DO ;
            }
            else if("DI" == back_str)
            {
                qDebug()<<"***UO**DI[]***"<<endl;
                type = WAIT_UO_DI ;
            }
            else if("RO" == back_str)
            {
                qDebug()<<"***UO**RO[]***"<<endl;
                type = WAIT_UO_RO ;
            }
            else if("RI" == back_str)
            {
                qDebug()<<"***UO**RI[]***"<<endl;
                type = WAIT_UO_RI ;
            }
            else if("SO" == back_str)
            {
                qDebug()<<"***UO**SO[]***"<<endl;
                type = WAIT_UO_SO ;
            }
            else if("SI" == back_str)
            {
                qDebug()<<"***UO**SI[]***"<<endl;
                type = WAIT_UO_SI ;
            }
            else if("UO" == back_str)
            {
                qDebug()<<"***UO**UO[]***"<<endl;
                type = WAIT_UO_UO ;
            }
            else if("UI" == back_str)
            {
                qDebug()<<"***UO**UI[]***"<<endl;
                type = WAIT_UO_UI ;
            }
            else if("R" == back_str)
            {
                qDebug()<<"***UO**R[]***"<<endl;
                type = WAIT_UO_R ;
            }
        }
        else if("UI" == front_varStr)
        {
            qDebug() << "****UI***"<<endl;
            if("ON" == back_str)
            {
                qDebug()<<"***UI**ON***"<<endl;
                type = WAIT_UI_ON ;
            }
            else if("OFF" == back_str)
            {
                qDebug()<<"***UI**OFF***"<<endl;
                type = WAIT_UI_OFF ;
            }
            else if("DO" == back_str)
            {
                qDebug()<<"***UI**DO[]***"<<endl;
                type = WAIT_UI_DO ;
            }
            else if("DI" == back_str)
            {
                qDebug()<<"***UI**DI[]***"<<endl;
                type = WAIT_UI_DI ;
            }
            else if("RO" == back_str)
            {
                qDebug()<<"***UI**RO[]***"<<endl;
                type = WAIT_UI_RO ;
            }
            else if("RI" == back_str)
            {
                qDebug()<<"***UI**RI[]***"<<endl;
                type = WAIT_UI_RI ;
            }
            else if("SO" == back_str)
            {
                qDebug()<<"***UI**SO[]***"<<endl;
                type = WAIT_UI_SO ;
            }
            else if("SI" == back_str)
            {
                qDebug()<<"***UI**SI[]***"<<endl;
                type = WAIT_UI_SI ;
            }
            else if("UO" == back_str)
            {
                qDebug()<<"***UI**UO[]***"<<endl;
                type = WAIT_UI_UO ;
            }
            else if("UI" == back_str)
            {
                qDebug()<<"***UI**UI[]***"<<endl;
                type = WAIT_UI_UI ;
            }
            else if("R" == back_str)
            {
                qDebug()<<"***UI**R[]***"<<endl;
                type = WAIT_UI_R ;
            }
        }

        lineOut.waitInstruct.type = type;
        lineOut.waitInstruct.front_addtype = patAddressType(front_str);
        lineOut.waitInstruct.front_val = front_i;
        lineOut.waitInstruct.operatorType = patOperatorType(operStr);
        lineOut.waitInstruct.back_addtype = patAddressType(back_str2);
        lineOut.waitInstruct.back_val = val_i ;

        if("TIMEOUT" == proStr)
        {
            lineOut.waitInstruct.timeOutFlag = TIMEOUT_EXIST;
            if("LBL" == proStr2)
            {
                lineOut.waitInstruct.jumpProcess.jumpLabelStr = proStr3;
            }
        }
        else
        {
            lineOut.waitInstruct.timeOutFlag = TIMEOUT_NOT_EXIST;
        }



        timeStr1 = strFilt(timeStr1);
        if("R" == timeStr1)
        {
            lineOut.waitInstruct.timeType = TIMEOUT_TIME_R;
//            qDebug() << __FUNCTION__<<"*******"<<__LINE__<<"======="<<timeStr1<<endl;
        }
        else if("AR" == timeStr1)
        {
             lineOut.waitInstruct.timeType = TIMEOUT_TIME_AR;
        }
        else
        {
            lineOut.waitInstruct.timeType = TIMEOUT_TIME_NONE;
        }

        QString timeStr3;
        timeStr3 = strFilt(timeStr2);
        if("[R[]]" == timeStr3)
        {
            lineOut.waitInstruct.timeOutType = INDIRECT;
        }
        else if("R[]" == timeStr3)
        {
            lineOut.waitInstruct.timeOutType = DIRECT;
        }
        else
        {
            lineOut.waitInstruct.timeOutType = TYPE_NONE;
        }
//        qDebug() << __FUNCTION__<<"*******"<<__LINE__<<"======="<<timeStr1<<"====="<<timeStr2<<"======"<<timeStr3<<endl;

        float regValue = (float)strToDouble(timeStr2);

        lineOut.waitInstruct.waitTime = regValue;
    }
    else if((match = rx13_3.exactMatch(programStr)) == true)
    {
        lineOut.waitInstruct.type = WAIT_R;
        QString rValStr;
        rValStr = strFilt(rx13_3.cap(3));

        int value_i = strToInt(rx13_3.cap(3));

        lineOut.waitInstruct.back_addtype = patAddressType(rValStr);

        lineOut.waitInstruct.back_val = value_i;
    }
    else if((match = rx13_4.exactMatch(programStr)) == true)
    {
        lineOut.waitInstruct.type = WAIT_DEAD;
    }

    return 1;
}

int ProgramRegExp::patErr(QString programStr, Line &lineOut)
{
    lineOut.type = ERR;
    qDebug()<<"不识别的指令行"<<programStr;

    return 1;
}

ADDRESSING_TYPE ProgramRegExp::patAddressType(QString str)
{
    ADDRESSING_TYPE addrType;
    if("R[]" == str)
    {
        addrType = INDIRECT;
    }
    else
    {
        addrType = DIRECT;
    }

    return addrType;
}

IF_OPERATOR_TYPE ProgramRegExp::patOperatorType(QString str)
{
    IF_OPERATOR_TYPE operatorType;

    if(">" == str)
    {
        operatorType = GREATER;
    }
    else if(">=" == str)
    {
        operatorType = GREATER_EQU;
    }
    else if("=" == str)
    {
        operatorType = EQU;
    }
    else if("<=" == str)
    {
        operatorType = SMALLER_EQU;
    }
    else if("<" == str)
    {
        operatorType = SMALLER;
    }
    else if("<>" == str)
    {
        operatorType = NOT_EQU;
    }

    return operatorType;
}

